Things I Learnt The Hard Way - If You Know How To Handle It, Handle It

1 minute read Published: 2019-06-24

If you know an error can occur, then you should handle it properly, instead of ignoring it.

This is the opposite point of let it crash: You're writing some code that you know it can crash in a certain way, what should you do? Well, the answer is simple: handle it, not ignore it.

If we go back to the fact that Java will describe every single exception that can be thrown by a function, you should handle each exception, no excuses.

If you're using Python, then you should capture the exceptions you know how to handle, no exceptions -- and tying with the previous point, if you don't know how to handle them, you should not capture them in the first place.

But, no matter what language you're using, if you know an error/exception can occur, deal with it. If you have to save the content of the user somewhere else, log it to be reprocessed later or even just show an error message, do it.

Although I seriously meant it, it doesn't mean you have to remember every single exception/error code and what it means when calling a function. You can write code that will actually go through the happy path and later fill the blanks. Or even, when you're working on another part of the code, if you remember another problem, just write on a post-it and add the handling later. The important bit is not to forget to handle it.

<< It's Better To Let The Application Crash Than Do Nothing
 
Types Say What You Data Is >>