13 ms·
> You can toss it, which works a little differently: it traverses the stack until you reach a matching catch block, but then you can use the return keyword to g
by amluto 3y ago
> You can toss it, which works a little differently: it traverses the stack until you reach a matching catch block, but then you can use the return keyword to go back to where the value was tossed from.
>
> I know, it's cursed using return in this unusual way. Again, sorry, I didn't make you keep reading. But, the reward is that since you got here, you get to see how we can use these to create control flow.
Maybe calling it 'return' is cursed, but this concept isn't cursed at all. These are resumable exceptions, and I used to love them! Windows supports them natively, although I don't think they're widely used. Here's the C/C++ extension for Window's native "structured exception handling", and ordinary C++ exceptions are built on top of it:
https://learn.microsoft.com/en-us/cpp/cpp/structured-exception-handling-c-cpp?view=msvc-170 https://learn.microsoft.com/en-us/cpp/cpp/structured-excepti...
It supports:
> Recognize the exception but dismiss it (EXCEPTION_CONTINUE_EXECUTION).
And as a kernel programmer, I really like resumable exceptions -- most hardware exceptions are resumable, and the kernel uses them extensively. When you get a page fault, that's an exception, and the kernel has a handler, and the control flow, um, yeets to the handler, and the handler, well, returns (or exits or whatever you want to call it) right back to the exception site.
And POSIX signals support this too -- it's even the default behavior when a signal handler returns. (POSIX signals suck.)
- andrewflnr 3y agoYeah, it would be 90% less cursed if she replaced "return" with "resume". But I get the impression she's going for the cursed aesthetic, so...