I have been working on an Android app which uses try/catch
frequently to prevent it from crashing even on places where there is no need. For example,
A view
This is bad for multiple reasons:
findViewById
throws an Exception? Fix that (and tell me, because I've never seen this) instead of catching.Exception
when you could catch a specific type of exception. If an app goes into a bad state, it is much better for it to crash than for it to chug along in its unusable state. When one sees an NPE, one shouldn't just stick in a null check and walk away. The better approach is to find out why something is null and either stop it from being null, or (if null ends up being a valid and expected state) check for null. But you have to understand why the issue occurs in the first place.