Quantcast
Channel: Net Knowledge
Viewing all articles
Browse latest Browse all 25

Catch First Chance Exceptions to debug CAB Pub/Sub Events

$
0
0

Debugging the Composite UI Application Block EventBroker can be a lesson in frustration. Often, an event subscription can do something substantial such as show a View or run a WorkItem. Should the event subscriber throw an exception, you get a not-so-helpful exception message caught at the publisher that reads something like "One or more exceptions occured while firing the topic 'YourEvent'". Gee, thanks. No stack. No inner exception. So how do you debug this sucker?

Of course, you could trace through your handler, line-by-line, but there is a better way. The trick is to catch first chance exceptions. Whenever you are running in debug mode in Visual Studio and an exception occurs you can control what happens. By default the exception will be thrown and handled by your application's code exactly as it would be at runtime in the production app. But, toggle a debugger setting and you can now tell Visual Studio to jump into the debugger at exactly where the exception occured with the stack at exactly the point BEORE the exception is thrown! This is a first chance exception because you have a chance to debug it before the exception happens. Its a great productivity tool, ESPECIALLY when you work on a team where some members love to eat exceptions!!! Now you can actually see the crap that your fellow programmers have swept under the rug and you can now properly debug your app.

Here's how to enable this magic.
1. In Visual Studio, press Control+Alt+E. You get the Exceptions window.
2. Notice that next to Common Language Runtime Exceptions, Thrown is not checked. Check it off at this level to debug into all CLS Exceptions or drill down if you are only interested in specific exception types.
3. Click Ok

Now you are in debugging bliss. Whenever an exception happens the Visual Studio debugger will be happily pointing you to exactly the source of the problem.

 


Viewing all articles
Browse latest Browse all 25

Trending Articles