tags:

views:

7

answers:

1
[ScriptableMember()]
public void HighlightEditsForCode(object xml)
{
  //Do Stuff
}

I have a scriptable member function. I throw an exception from within this function.

It doesn't trigger the application.UnhandledException event...

something must be handling this event... how can I prevent this and have the unhandledexception event be called?

Or at least avoid having my application crash and display a javascript error?

+1  A: 

You can't really prevent this behaviour, the error does not go "Unhandled" from the .NET perspective. There will be an error handler at the boundary between Javascript and .NET, here the .NET error is "handled" as it is converted to a Javascript error. This javascript error is then thrown in the script engine.

The only way around this is to always include a try..catch handler in anything marked as a ScriptableMember. If such a member is also called from .NET code then create surrogate member just to be called by script. Example:-

[ScriptableMember(ScriptAlias="HighlightEditsForCode")]
public void HighlightEditsForCodeScript(object xml)
{
  try
  {
    HighlightEditsForCode(object xml);
  }
  catch(e)
  {
    CallSomeEquivalentToUnhandledError(e);
  }
}

public void HighlightEditsForCode(object xml)
{
  // Do Stuff
}
AnthonyWJones