Like most of us, my applications usually have a global unhandled exception handler, in order that the inevitable unhandled exception wonâ€™t crash the system.
The problem with this is that by the time you get to the exception handler, youâ€™ve completely lost the context of what was happening. Youâ€™re in an isolated, global context, away from any window.
What you really want is to get immediate feedback when thereâ€™s been a problem, so you can react appropriately for the situation. For example, failure to load a customer list could be handled by trying again, up to a maximum number of attempts, before informing the user that the list couldnâ€™t be loaded. By contrast, if they were trying to save an individual customer (presumably from a customer details window), youâ€™d react differently.
Around a year ago, whilst contemplating this issue, I had an idea that turned out to be an excellent answer to the problem. It turned out that this wasnâ€™t an original idea (it was too obvious for that), but as I hadnâ€™t come across it before, I didnâ€™t know that at the time.
In this post, I describe the Fallible type, and how it can be used (really easily) to simplify and improve your exception handling.