Although in Error Handling — Problem Overview, Russ Cox does a great job motivating the need for lighter-weight error handling, I have a few concerns with the catch
and handle
mechanisms proposed for Go2. I most dislike the fact that only one handler can be active at any point in the code. I largely disapprove of recoverable errors not being supported. And I'm not particularly fond of check
being hard-wired to work only with type error
.
In my counter-proposal, I call for a single new keyword, returnfrom
:
ReturnFromStmt = "returnfrom" Label [ExpressionList] .
The semantics is that returnfrom
behaves like a return
appearing in the same scope as a given label. It's therefore a bit like a goto
but supports the handler nesting that Cox's article calls out as important for proper cleanup.