Functional Error Handling

Balraj Singh
techtron
Published in
5 min readOct 21, 2018

--

Exception & Async can't go hand in hand

Till now we have been mostly talking about Functional Concept like Composition and Currying with some practical usage. But for a change, I thought to pick a topic which developers encounter in an everyday scenario.

Exceptions in OOP centric languages

Throwing an exception and handling them in a try catch block is something which every developer encounter quite often. But if u forget to handle an exception “all hell breaks loose” at runtime. This becomes one of the most commons reasons for an application to crash in production or become unresponsive. Making your application looks bad.

But Why would I forget to handle an exception?

An excellent question. But a simple answer. Exceptions are implicit.
Few points which make exception lead to the incorrect and dangerous code are:-

  • The compiler doesn’t complain if you don’t handle it. Owing to exceptions implicit nature in every sense.
  • Function signature might tell us that a function can throw an exception with a keyword called as throws in Java or Swift but doesn’t clearly explain what kind of exception to handle.
  • Runtime Exceptions like nullpointerexception or dividebyzeroexception are generated by wrong data. Hence…

--

--

Balraj Singh
techtron

Software Engineer, Blogger, Tea Lover and Learner