fholm / IronJS

IronJS - A JavaScript implementation for .NET
http://ironjs.wordpress.com
Apache License 2.0
680 stars 79 forks source link

Error handling should be improved #34

Open belf opened 13 years ago

belf commented 13 years ago
function a() {
    return new not_defined_yet();
    }
a();

While running the script above the valid error raises (ReferenceError: not_defined_yet is not defined). There are two problems: 1) The error which was thrown is System.Reflection.TargetInvocationException. An user would expect IronJS.UserError or similar (it is not serious but rather annoyance) 2) Column and Line fields of IronJS.UserError do not direct to the place where an error occurs (it is more serious, hard to figure out where an error is in a code)

The full source code is the following:

using System;
using IronJS;

namespace isronjs.test
    {
    public class test
        {
        public static string run()
            {
            try {
                const string script = @"function a () {
                        return new not_defined_yet();
                    }
                a();
                ";

                var context = new IronJS.Hosting.CSharp.Context();

                var result = context.Execute( script );
                return TypeConverter.ToString(BoxingUtils.JsBox(result));
                }
            catch ( Exception e )
                {
                if ( e.InnerException != null && e.InnerException is UserError )
                    {
                    var user_error = e.InnerException as UserError;
                    Console.WriteLine( "USER ERROR (line:{0},column:{1}): {2}", user_error.Line, user_error.Column, e );
                    }
                else
                    Console.WriteLine( "ERROR:{0}", e );
                }
            return null;
            }
        }
    }
fholm commented 13 years ago

Thanks for reporting this, adding it to the 0.2.1 milestone

fholm commented 13 years ago

1) is fixed in commit 7c9f57e84

belf commented 13 years ago

Wow! That is really quick, Thanks!

fholm commented 13 years ago

We're working on improving the line/column reporting, it's pretty bad no doubt, it'll get a lot better. It's also a requirement for the planned integrated VS debugging