3 ms·
I hear what you're saying, but I confess I don't 'get' exceptions. On the spectrum of ways to report an error (C return values, Swift errors, C++ exceptions, L
by ken 8y ago
I hear what you're saying, but I confess I don't 'get' exceptions. On the spectrum of ways to report an error (C return values, Swift errors, C++ exceptions, Lisp conditions), they seem like an arbitrary spot in the middle that doesn't really give me the best of anything. They're neither as efficient as C/Swift, nor as flexible as Lisp.
Once you're going to go to the effort to walk the stack, why not give the caller the opportunity to continue? It's a huge increment in power for what seems like a minimal addition.
- dllthomas 8y ago> They're neither as efficient as C/Swift, nor as flexible as Lisp. My understanding is that, at the cost of a significant penalty for the (hopefully rare) exceptional case, error handling with exceptions can be faster than returning values like in C in the (hopefully common) successful case.
- kazinator 8y agoIn fact, the addition is almost a subtraction. To make restartable exceptions to work, all you need is a way to search for points without unwinding the stack, and invoke closures there. In TXR Lisp, I unified conditions and restarts into a single mechanism, which is called exceptions. There are two kinds of handling frames: ones for which an unwinding takes place first, and ones which just intercept the search. Both are identified by an exception symbol which exists in an inheritance hierarchy. It's all documented in detail here: http://nongnu.org/txr/txr-manpage.html#N-0146B946 http://nongnu.org/txr/txr-manpage.html#N-0146B946 There are dialect notes comparing with ANSI CL, and an example program shown in both TXR Lisp and a CL translation for comparison.