4 ms·
I'd prefer to separate the concepts of "exception" and "unwinding". In languages such as C++ and Java, raising an exception defaults to an unwinding only if no
by Findecanor 3y ago
I'd prefer to separate the concepts of "exception" and "unwinding".
In languages such as C++ and Java, raising an exception defaults to an unwinding only if not handled within the same function that raised it.
Then there are languages with resumable exceptions, and languages wherein unwinding is considered normal control flow as "shortcut returns".
- madsbuch 3y agoCan you give an example of languages with resumable exceptions (just want to check it out)?
- olmo23 3y agoRacket
- Findecanor 3y agoCommon Lisp, Smalltalk, Ruby, Elixir, ... A handler for a resumable exception is passed down the call stack, rather than an object being passed up the call stack to the handler. In some languages the handler can conditionally decide whether to resume back into or restart the block that raised the exception, or to cause an unwinding of the stack. In other languages, the action is fixed per exception type. (`try ... rescue`)
- randomdata 3y agoAlso, "exceptions" and "exception handlers". Exceptions are merely the record of the programmer's mistake. Essentially an error, except an error that could have been caught at compile time given a sufficiently advanced compiler. Exception handlers provide a control flow for dealing with exceptions, which may include unwinding. Exception handlers, while primarily intended for use by exceptions, are not necessarily restricted to exceptions. Often programmers use them to move other things around, most notably errors.
- layer8 3y agoMost places where exceptions are thrown do not want to handle the case of resumption. Being usefully-resumable requires careful design at the site where the exception occurs, it isn’t something you can just throw in (no pun intended) as a general feature of all exceptions. From an interface-contract point of view, exceptions model the case that an operation cannot complete normally. Any mechanism that enables an operation to complete normally after all upon encountering an error condition, should better be modeled with a separate language feature, for example with callbacks specific to the concrete error condition.