Larry Wall wrote:
The Perl 6 perspective on this is that error values should be allowed to be as "interesting" as you like. The lower level routine goes ahead and pregenerates the exception object but returns it as an interesting error value instead of throwing it. Then the calling code can just decide to throw the unthrown exception, or it can generate its own exception (that perhaps includes the unthrown exception). In any case, you get a better error message if you include all the relevant facts from the lower-level routine, and those tend to get lost with scalar error values. By returning an object you still a simple test to see whether there's an exception, but you're not limiting the information flow by assuming all the information passes through whatever scalar is functioning as the boolean value of "oops". In any case, this would certainly make it easier to put Perl 6 on top. :)
Aye, async operations will return a status object and only a status object (a multi-layered object that contains integer status, an unthrown exception/error object, the return value after the async operation is complete, etc).
So the question is mainly about sync ops. The PDD currently says that sync ops return integer status codes and async ops return status objects, but that's a potentially confusing difference in behavior between the two and potentially added and unnecessary complexity for compiler writers trying to generate code for both sync and async ops.
If both sync and async ops returned status objects, it would be conveniently consistent. It would also be annoyingly heavyweight for a simple synchronous operation, but then the biggest cost for I/O ops is generally the I/O.
The remaining question is: many sync I/O ops return a value in addition to the status. Some return values are integers, many are strings, some are PMCs. Should we return just the status object from synchronous ops like we do for asynchronous ops (retrieving the return value from the status object), or return a status object followed by the return value? What's easiest for the compiler writers? What's easiest for people writing low-level libraries in PIR?
Allison