|
|
|
|
|
by prevedmedved
2992 days ago
|
|
The dislike comes from the fact that some people abuse exceptions as a flow control mechanism. This is due to the "everything is a nail if you have a hammer" problem: exceptions and RAII is a resource lifetime control mechanism that every modern and sane language should have, but very few programmers are ready to reason in terms of resources and lifetimes instead of instructions. |
|
A sibling comment hints at the way out:
> For exceptions to work predictably, all mutation within a try-catch block should be captured in a transaction that can be rolled back.
The instant an exception can be raised from an area in code is the instant you need to make that entire area into functionally-pure side-effect-free logic, so that you can reason about it even when the exception is raised.
And then you've got a function that could just as well return an Either<Result, Error> -- what a strange "coincidence"!