Exceptions from C# functions

Nov 24, 2009 at 6:55 AM

Something to think about:  What happens when Javascript calls a .Net function and it throws an exception?

Right now, the JintEngine just throws a TargetInvocationException back to the host .Net application.  This is a concern, because as I walk the stack trace, I see things like "ExitScope" that aren't in "finally" blocks, and thus I suspect that the JintEngine object is in a bad state after it calls a .Net function that throws an exception.

Furthermore, the Javascript language has try-catch-throw, thus it's perfectly reasonable to expect that .Net exceptions are "catchable" in Javascript, and that Javascript in Jint can throw exceptions back to its host .Net application.

Thus:

  • When Javascript calls a .Net function and it throws an exception, how should Javascript be able to catch it?
  • When Javascript calls a .Net function and it throws an exception, how should that be passed to the host .Net application if it's unhandled in Javascript?  (Rhino wraps it.)
  • What about Javascript exceptions that are uncaught?  (I haven't played with these so I'm unaware if Jint does Javascript exceptions.)