3 ms·
Way too little information to base an answer on in your question. However my general approach to exception handling and try catch is to group the error into two
by zaphar 5y ago
Way too little information to base an answer on in your question. However my general approach to exception handling and try catch is to group the error into two possible categories:
1. Errors that someone up the call chain should be handling.
2. Errors that should abort the process or application entirely. Unrecoverable errors basically.
For the first one it's important to model the exception correctly. You want to provide enough information for the someone in the call chain to properly handle it.
For the second one you just let the exception bubble all the way up. Crashing may be the only correct course of action.
In general if you are using try catch in place of `if obj == null` then you aren't really saving any effort in typing and your solution is way more expensive than the null check.
- 999900000999 5y agoLet's say you want to create a new note, with a photo. Right now I use the same UI page to create notes as to view them. I just added the photo viewer and noticed the app kept crashing whenever I wanted to create a new note. When I figured this out, I just put a try catch block around the photo viewer. It still works once you create the note. For this particular application all notes have photos.