Re:JEP draft: Exception handling in switch
by wbl on Friday April 19, 2024 @04:33PM
(#40091620)
Throws are nonlocal control transfer, not types. The interaction with the rest of the language is entirely different.
[ Parent
| on HN ]
Re:JEP draft: Exception handling in switch
by ackfoobar on Friday April 19, 2024 @05:39PM
(#40092217)
Rather than looking at what the (abstract) machine does
- throws are nonlocal control transfer
- result types are adding a tag to the data or error
Think about whether the two can express the same things, and whether one can be translated to another without losing information.
How are throws non-local? They simply pop a stackframe, the exact same way as the `return` keyword. Then the calling method gets to decide what to do, exceptions just have an implicit “unwrap-or-return/bubble up”.
Exceptions are nothing like gotos/long-jumps, it’s just “pressing escape key once vs keeping it pressed”, basically.