3 ms·
So then you make a pure function `throw_exception` and now you can throw from impure code.
by mike_hock 4y ago
So 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).