开发者

Exceptions and Scriptablemember

[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 m开发者_如何学Goust 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?


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜