Handling Runtime Error Messages in IE and Mozilla

Synchronous method calls in Silverlight scripting applications can be placed in a try/catch block to handle errors thrown by the called method. An error message is included in the error object that is passed to the catch block. The problem is that Internet Explorer and Mozilla browsers have slightly different behaviors in how this message is exposed.

Here's a short function you can call from your catch block to get consistent error message regardless of which browsers the Silverlight scripting application is running in.  From the catch block, just pass the error object to the helper function and it will return the correct error message.  For more information on error handling in Silverlight Beta 1.0, see the Silverlight Error Handling overview.

 
// Helper function to get consistent error messages 
// for IE and Mozilla browsers.
function getAgErrorMessage(e)
{    var message;
    // Get the message for IE browser.
    if (e.message != null)
    {
      var icode = e.number < 0xFFFF;
      message = icode + " : " + e.message + "\n";
    }
    // Get the message for Mozilla browser.    else    {       message = e.toString( );    }     return message;}
  --Brian
   Silverlight SDK Team