DEV Community

Discussion on: Exception handling is an Antipattern | Avoid when possible

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

I'm sorry, I could not finish reading. There are so many things wrong with this I just stopped.

You are completely misunderstanding exceptions. Exceptions are the mechanism the language/application uses to inform us that something went wrong. Nobody, and I mean nobody has ever encouraged me to ignore the possibility of exceptions. The key word here is exception. It is an exceptional case, and it is therefore good and nice to be outside of the happy path.

Exceptions are also very helpful: Their main purpose is to alert, and alert they do indeed. They are alerting you to the possiblity that (taking from your example) a file is read-only or non-existing. But most importantly they are telling you that your application is not stable.

Maybe you get the idea that programmers are encouraged to ignore them because you see so many junior and mid developers adding try..catch blocks everywhere, sometimes with an empty catch block. Now that's the anti-pattern. Not the exceptions themselves.

Collapse
 
ziaulhasanhamim profile image
ziaulhasanhamim

I think you got my point wrong. I clearly state that exception handling is an antipattern not exception itself. Also, I mentioned that exceptions should only be used if something gone horribly wrong not just for control flow. They have all sorts of disadvantages that I pointed out. For these demerits it's rare to see exception as a feature in modern languages unless they are successor to any old language, and they have to maintain compatibility.

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

While I get your clarification point, I cannot shake the feeling that if I agree with you, I'll be agreeing that exception handling must go away altogether. This is why I drove myself to commenting. Saying "exception handling is an anti-pattern" is too bold of a statement.