IronJS icon indicating copy to clipboard operation
IronJS copied to clipboard

Error handling should be improved

Open belf opened this issue 14 years ago • 4 comments

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;
            }
        }
    }

belf avatar Apr 20 '11 16:04 belf

Thanks for reporting this, adding it to the 0.2.1 milestone

fholm avatar Apr 20 '11 16:04 fholm

  1. is fixed in commit 7c9f57e84

fholm avatar Apr 20 '11 16:04 fholm

Wow! That is really quick, Thanks!

belf avatar Apr 20 '11 16:04 belf

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

fholm avatar Apr 20 '11 17:04 fholm