DEV Community

Discussion on: Why Functional Programmers Avoid Exceptions

Collapse
 
gdenn profile image
Dennis Groß (he/him)

I also reached a point in my career where I am convinced that writing as much pure code (in a functional programming sense) as possible-/feasable is the way to go.

It just delivers code that is easier to test, does not require deep understanding of every function (absence of side effects) and contributes to the overall code quality.

But as you already wrote, throwing exceptions is not contradictory to the functional programming paradigm as long as I declare what can be thrown in the function header.

In this sense, exceptions become just another return value of the function. At the end the way I access these "Exception return values" differs.

Problematic are the languages that cannot declare what Exceptions may be raised e.g. Python, Ruby...etc.

I think using real Ok -/ Error return values for such languages makes 100% sense. I also would not advocate against it in languages such as Java where we can declare what exceptions can be expected from a function. But throwing exceptions in such languages is a fine practice nevertheless (my opinion of course).