-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement exceptions, throw, and try/catch/finally #65
Comments
I'm thinking we will need a Rethrowing would be an option...
...but not such a good one, because that involves throwing away important stacktrace between the original throw site and the |
Just pointing out that dcad411 (still out in a branch) adds I think the attempt is good, but as we merge these changes into |
This was `die` for a short while in a branch, but #65 says we should call it `throw`. Also introduces the Val::Exception type, which is the only thing you can throw. (In the branch it was Val::Str, but that's deprecated now with extreme prejudice.)
This was `die` for a short while in a branch, but #65 says we should call it `throw`. Also introduces the Val::Exception type, which is the only thing you can throw. (In the branch it was Val::Str, but that's deprecated now with extreme prejudice.)
This was `die` for a short while in a branch, but #65 says we should call it `throw`. Also introduces the Val::Exception type, which is the only thing you can throw. (In the branch it was Val::Str, but that's deprecated now with extreme prejudice.)
|
Two things. First: I think it was a mistake to ever talk about several I know that sounds a bit single-minded, but I've come to the conclusion that it's nevertheless correct. There should be only one |
Second: I've become convinced that Perl 6 has it right with the I just went back to A04 to remind myself why I believe this to be correct. Also (and this is also being hinted as a reason in A04), having a separate |
Perl 6 does
die
and Python doesraise
, so there's no consensus between the two. Let's go with Java'sthrow
, because it's a nice conjugate withcatch
. And it's pretty common.So that we don't block on #32, let's also introduce an
Exception(str)
built-in function which can produce exception objects. After we get proper classes we can expand this into being able to create custom exception classes.The
try
block can be followed by zero or morecatch
blocks with a declared expression parameter.Under #33 there can be several
catch
blocks with type declarations.(Catching something which cannot possibly be caught because it's caught at earlier steps is a compile-time error. Which means actually having more than one
catch
block without #33 will always be a compile-time error.)Similarly, there can be zero or one
finally
blocks. The semantics of which should be "the usual":finally
runs regardless of whether an exception was caught by thetry
or notfinally
runs regardless of whether areturn
(or other control exception) happened inside thetry
return
happened inside thetry
, andfinally
also has one, the latter winsExceptions thrown in a
catch
or afinally
are not caught by any of thecatch
blocks.The text was updated successfully, but these errors were encountered: