|
|
|
|
|
by Scandiravian
2122 days ago
|
|
Throwing an error is implicitly making a decision, that there's no way to recover to a working state for the program A lot of times that's a perfectly fine decision, but six months down the road when the code has grown a lot, you might find an alternative way to get the resource on a fail If you made a decision to throw an exception immediately after failing to get the resource, you then have to either rewrite the logic, which can be very expensive, or catch the error, which bloats the code (throwing the exception is now redundant and is fixed by adding code that catches that exception) By instead putting the return value in an appropriate monad, you can postpone throwing the exception until you're sure that there's no way to recover Throwing an exception is still something that's necessary occasionally, but it should not be done until there's no possible way to recover, and be done in a way, so it's easy to rewrite if a way to recover becomes available at some future point in time |
|