Think Before You Async
More and more nowadays there is a push to run more application code in an asynchronous manner to prevent blocking the UI thread and making the application unresponsive. As the need for this type of programming becomes more prevalent thankfully the APIs to do so have also become easier to implement. The last part (easier APIs) has led to more and more async code sprinkled through an application like the little candies on top of donuts. Unfortunately the easier APIs also mean it’s easier to abuse the functionality by not properly implementing exception handling.
All of these async sprinkles can sink an application fast as code may be exploding left and right with the application user non the wiser. From the users perspective everything seems like it’s ok (i.e. the app doesn’t abort or show error dialogs) but nothing seems to be working.
I’d like to take a moment to look at various ways to async a task and highlight the exception handling issues related to each. To do this I am going to use the following program framework. My goal each time is to first see whether an unhandled exception occurs and if so then to handle it appropriately.
Thought this a great, in-depth article on async and some the perils and pitfalls of async dev.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)