DEV Community

Discussion on: Exceptions Considered Harmful

Collapse
 
pianomanfrazier profile image
Ryan Frazier

Languages like Go, Rust, and Haskell don't have exceptions and they figured out these problems.

I knew this article would ruffle feathers when I wrote it. I wanted to present an alternative approach. I prefer explicit handling of uncertainty rather than leaving escape hatches throughout the code.

Time has shown us that no matter how careful we are Java programs will eventually throw an uncaught nullexceptionpointer. We need better mental models not more disciplined programmers.

Collapse
 
ashleyjsheridan profile image
Ashley Sheridan

I was in agreement with you about handling uncertainty properly, and exceptions allow you to do exactly that.

The fact is, we will undoubtedly need to work with 3rd party libraries et al in our code. If the language supports exceptions, then we will need to handle them. It makes sense to use them if we need to handle them at some point anyway.

Plenty of incredibly popular and powerful languages use exceptions to handle errors, that's their solution to handling the error problem. If Go & Rust don't, that's fine, it doesn't make them bad languages or mean that exceptions are bad or to be avoided.

Thread Thread
 
pianomanfrazier profile image
Ryan Frazier

My usual pattern with 3rd party libraries is to catch the exception immediately around the function call then convert it to a Result. Some functional libraries even have a helper function for this. See Purify's encase function gigobyte.github.io/purify/adts/Eit...