On Fri, Jan 05, 2007 at 10:59:59PM -0800, Allison Randal wrote:
: Jonathan Worthington wrote:
: >I suspect it's cheaper/easier for a compiler to generate code to check a 
: >return value and throw an exception of its own choosing, than it is to 
: >emit code to catch the exception and return the error value.

Depends on whether by "error value" you mean "scalar error value"...

: Yeah, I like that perspective. Implement the alternative that's easiest 
: to build on top of.

However, I think you can make it even easier to build on top of if
you take the third of those two alternatives...

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.  :)

Larry

Reply via email to