Welcome to MSDN Blogs Sign in | Join | Help

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
Published Wednesday, May 02, 2007 10:00 PM by wpfedevcon
Filed under:

Comments

# Silverlight Examples

During the weekend I spent some minutes to collect some of the greatest Silverlight examples. Most of

Tuesday, June 05, 2007 6:25 AM by Michael's Blog
Anonymous comments are disabled
 
Page view tracker