Skip to content

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

Closed
Daniel15 opened this issue Apr 26, 2014 · 4 comments
Closed

Comments

@Daniel15
Copy link

The MSIE engine catches MsieJavaScriptEngine.JsRuntimeExceptions but does not catch MsieJavaScriptEngine.ActiveScript.ActiveScriptExceptions (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.

@Taritsyn
Copy link
Owner

Hello, Daniel!

MsieJavaScriptEngine.ActiveScript.ActiveScriptException are catched (see ActiveScriptJsEngineBase.cs file).

MsieJsEngine class is sealed, because I see no point in inheritance from it.

Give an example of custom behaviour.

@Daniel15
Copy link
Author

Hey @Taritsyn, it looks like CallFunction doesn't wrap exceptions:

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:

Caught System.Reflection.TargetInvocationException
 --> MsieJavaScriptEngine.ActiveScript.ActiveScriptException

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 :)

@Taritsyn
Copy link
Owner

This bug fixed in the JavaScriptEngineSwitcher.Msie v1.1.6.

@Daniel15
Copy link
Author

Thank you @Taritsyn! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants