3 ms·
Throws are nonlocal control transfer, not types. The interaction with the rest of the language is entirely different.
by wbl 3y ago
Throws are nonlocal control transfer, not types. The interaction with the rest of the language is entirely different.
- ackfoobar 3y agoRather 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.
- kaba0 3y agoHow 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.