views:

77

answers:

2

What's the best exception to throw if a Silverlight app fails initialization or fails to load?

Or should I not throw an exception at all?

A: 

I personally don't like the UI that IE shows when a Silverlight application throws an unhandled exception. It has a very small window that shows the exception text but the options present certainly aren't user friendly. I guess this is a matter of opinion, but my preference is to catch any exceptions during initialization and try to present the user with a meaningful description of what happened. Typically I store some settings in isolated storage, so one helpful message might describe how to clear the iso store for my app to eliminate some sort of configuration problem. As long as you can provide the user with some meaningful steps to fix the problem, or at least who to contact if they can't, I'd say it's better not to throw exceptions during initialization that would cause the app to fail to load.

James Cadd
+1  A: 

In my experience, load/initialization failure sometimes results in a managed exception, sometimes not. In some cases, the exception or failed condition may only be accessible at the client through javascript. In the event of an exception that comes from the entire app failing, there should be some indication to the user that the app failed completely.

You should consume and handle exceptions that are thrown from init/load failure. Explicit throwing of exceptions should be reserved for conditions where there is a violation of business logic, communcations failure, or other truly exceptional case.

Dave Swersky