IronJS
IronJS copied to clipboard
Error handling should be improved
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:
- The error which was thrown is System.Reflection.TargetInvocationException. An user would expect IronJS.UserError or similar (it is not serious but rather annoyance)
- 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;
}
}
}
Thanks for reporting this, adding it to the 0.2.1 milestone
- is fixed in commit 7c9f57e84
Wow! That is really quick, Thanks!
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