DEV Community

loading...

Discussion on: Errors Are Not Exceptions

Collapse
shalvah profile image
Shalvah

What problem I see in returning errors is that there can be many levels of such passing error around until we find a place which deals with that finally. With try catch we can just jump to the place where we handle it.

I love this too about exceptions. When my code mixes the actual logic with the error handling (if err != nil and the like), it gets very difficult to read. I like that try/catch lets the happy path flow naturally and you handle exceptions in one place.

Of course, you need to remember to handle the errors, but that's a price I'm willing to pay, rather than passing error objects around.