Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I recently took over an android project that had this design pattern... they guy said that the google analytics showed the crash was originating from a certain class so he wrapped every line in try/catch. It was like 1500 lines long of that crap.
-
Exceptions should be used when something exceptional happens.
A lot of developers tend to use it as a dirty communication mechanism to talk back to some caller (ignoring all kinds of type restrictions in the process), or worse, as a stub for laziness.
It decreases the safety of your code, because before you know it you forget to catch something you're throwing, and the user gets an error -- which you then try to remedy by plastering all of your code with try/catch/throw/log/rethrow abominations.
In my opinion, in most cases your code should aim at handling edge cases through validation with feedback to the user, by sanitizing data, or by handling things in conditional statements.
Then you should have a smart exception logging mechanism for anything which manages to leak through unhandled, a system which doesn't bother the user too much, and logs plenty of detail so you can resolve it quickly (something like bugsnag, rollbar, sentry, etc)
Try/Catch doesn't fix stupidty! OR BAD CODE!
undefined