Python uses try/except, which I find annoying, but maybe it's just me.
We have a proof-of-concept try/catch syntax just to get something going in the C Rune compiler, and probably won't bother getting it working properly, because it can wait for the bootstrap. However, it would be nice to support the expected syntax that the bootstrap compiler will used. Right now, we just have:
try {
throw "No!!!"
} catch e {
println e
}
That's not going to be good enough, probably not even for the bootstrap. How about something like:
enum StatusCode : u8 {
Ok = 0,
Cancelled = 1,
Unknown = 2,
InvalidArgument = 3,
...
}
try {
handlePpc(rpc)
} catch (StatusCode.Unknown, msg) {
...
} catch (status: StatusCode, msg) {
...
} catch e {
println "Unhandled exception: ", e
throw e
}
This syntax would introduce "patterns" into Rune, where we can explode tuples more easily, like Python. It would allow:
(a, b) = (b, a)
Which is how we swap 2 variables in Python. It would also allow:
switch point {
(x, y) {
println x, ", ", y
}
}
I know we need this, but have put it off, hoping to build it in the bootstrap. There isn't much exception handling required in a compiler.