Monday, December 3, 2007

Silverlight 1.1 global page error handler

[This was originally posted at]

When writing Silverlight TruckWars, I was trying to figure out how to create a global error handler for a page. Eventually I saw the WebApplication.Current.ApplicationUnhandledException event, which I could hook up like so:


    public void Page_Loaded(object o, EventArgs e)
        WebApplication.Current.ApplicationUnhandledException +=
            new EventHandler


    void Current_ApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)


Note that Silverlight handles errors differently than ASP.Net. In ASP, you get the yellow error page with a detail exception message (by default). However, in Silverlight, it just stops executing your code and returns to the caller, leading to weird behavior.

No comments:

Post a Comment