18
ldrago
7y

Try/Catch doesn't fix stupidty! OR BAD CODE!

Comments
  • 1
    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.
  • 4
    At least they were TRYing...
  • 3
    @wmhilton I almost didn't CATCH your joke.
  • 3
    @ryanmhoffman It is - shall I say - an EXCEPTIONal joke
  • 3
    @wmhilton FINALLY someone gets me!

    @runfrodorun sorry I couldn't help myself.
  • 0
    @wmhilton time to stop posting
  • 1
    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)
Add Comment