3 ms·
In a new language, I'd like to see exceptions being allowed in pure code, but prohibited in non-pure code. (Non-pure here meaning code with side effects.) In p
by winter_blue 4y ago
In a new language, I'd like to see exceptions being allowed in pure code, but prohibited in non-pure code. (Non-pure here meaning code with side effects.)
In pure code, an exception could essentially be passed up, and transformed into an error return value at the point where it's called by non-pure code.
- mike_hock 4y agoSo then you make a pure function `throw_exception` and now you can throw from impure code.
- winter_blue 4y agoIn non-pure code, we would want to force the programmer to handle the exception. In this case, wherever `throw_exception` is called, the programmer would have to handle the exception, and either refactor the return value to indicate an error, change the return value to an Optional (and silently fail by returning an empty Optional), or cause/trigger a side effect (like terminating the thread/program termination early, with an exit code).