-
Notifications
You must be signed in to change notification settings - Fork 49
MsieJavaScriptEngine.ActiveScript.ActiveScriptException not wrapped #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello, Daniel!
MsieJsEngine class is sealed, because I see no point in inheritance from it. Give an example of custom behaviour. |
Hey @Taritsyn, it looks like using System;
using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.Msie;
using JavaScriptEngineSwitcher.Msie.Configuration;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
var config = new MsieConfiguration { EngineMode = JsEngineMode.ChakraActiveScript };
using (var engine = new MsieJsEngine(config))
{
engine.Execute("function foo() { throw new Error('Hello World'); }");
try
{
var result = engine.CallFunction<string>("foo", "bar");
}
catch (JsRuntimeException)
{
Console.WriteLine("Caught JsRuntimeException :)");
}
catch (Exception ex)
{
Console.WriteLine("Caught {0}", ex.GetType());
if (ex.InnerException != null)
{
Console.WriteLine(" --> {0}", ex.InnerException.GetType());
}
}
}
Console.ReadKey();
}
}
} Result:
My custom behaviour was going to be wrapping the exceptions in a derived class, so I didn't have to modify MsieJavaScriptEngine itself. I guess it's not common. I just dislike sealed classes :) |
This bug fixed in the JavaScriptEngineSwitcher.Msie v1.1.6. |
Thank you @Taritsyn! :) |
The MSIE engine catches
MsieJavaScriptEngine.JsRuntimeException
s but does not catchMsieJavaScriptEngine.ActiveScript.ActiveScriptException
s (which can occur if there's a syntax error). These should be wrapped in an appropriate exception class. This exception type is internal so I can't even catch them to handle them nicely at the moment.Additionally, why is the MsieJsEngine class sealed? This makes it a lot more difficult to add custom behaviour without forking the project.
The text was updated successfully, but these errors were encountered: