I’ve been trying to read more about what to do properly catching / handling exceptions, but I don’t think I’ve got it down. In fact, I think I’m getting much more confused and possibly implementing bad code. I don’t want to do that.
An example setup that I have been using:
- Mobile device makes a call to the WCF Service.
- WCF Service retrieves the data from the database, and if any errors occur on the database level, they are logged and I am sent an e-mail.
- WCF Service sends data (or a brief description of the exception) to the mobile device.
- The mobile device processes the data, and if any error occurs, throws the error up to the UI layer.
For a few of the exceptions, I created custom ones – service exception, authorization exception, so I can properly notify the user. If the service encountered an error or an IOException occurs, the user will be notified that ‘the data could not be retrieved.’
If, however, another error occurs – such as a JSON error, or anything like that ‘just in case’, the error is thrown to the UI layer and simply caught as Exception, since we don’t really need to user to know what happened, but that an error occurred.
Is this appropriate exception handling?
Are you seeing any problems?
In general, it makes sense to have some sort of catch-all that allows the user to keep working. This should be combined with appropriate handling for any showstoppers, to let the user down gracefully, and catch anything else that would make proceeding dangerous.