r/transprogrammer • u/definitelynotagirl99 • Jul 20 '24
Implementing exceptions
Just wanna know if anyone knows a more time-efficient way of implementing exceptions in a language than this or sees any issues with this design :3

handlethrow would exist separately for each try-catch clause
(obv this will only work for x86 but smth similar should work for all major architectures)
15
Upvotes
View all comments
Show parent comment
1
u/ato-de-suteru Jul 21 '24
I agree with the idea, but I wonder if there's a little confusion. Returning an error value instead of interrupting the program doesn't necessarily mean errors don't propagate up the stack, or even that every caller must necessarily handle such a value. Eg., in Rust you can let a function panic rather than explicitly handle an error, or do nothing with the error except return it immediately.
The main difference is that doing so is very explicit in the syntax or methods used and they can be tracked at compile time. It becomes impossible to call
xwithout knowing thatxmight fail and how.Or put another way, I find this less informative
than this
Certainly a docstring can be used with the first example, but LSPs don't consider docstrings when type-checking your code.