DEV Community

Peter Gašparík
Peter Gašparík

Posted on

Don't ignore caught exceptions

I had a really bad day because of a function, that ignored all caught exceptions. Code looks something like this and it was part of a third party library, that I was using. I didn't know about implementation details at the time.

function doSomething() {
    try {
        // some code
    } catch (err) {}

Debugging function like this, that never crashes and never prints any error messages, is a nightmare. I usually trust third party libraries and at first assume that problem has to be with my code. That’s why I spent hours debugging this.

So, what to do with exceptions? I think it's valid to let other programmers (those that use this library) to handle the exception. Especially, if you have no idea what to do with it.

What do you think? Is there a situation where this is acceptable? Maybe production environment? I personally don't think so, because you want to know about errors in production and store them somewhere.

Discussion (0)