开发者

Exceptions and Scriptablemember

开发者 https://www.devze.com 2023-01-11 14:15 出处:网络
[ScriptableMember()] public void HighlightEditsForCode(object xml) { //Do Stuff } I have a scriptable member function.I throw an exception from within this function.
[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

精彩评论

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

关注公众号