[Ironruby-core] Determining line number of runtime errors

Benjamin van der Veen lists at ruby-forum.com
Tue Dec 16 14:52:08 EST 2008


Curt Hagenlocher wrote:
> I think the logic for this is all in RubyExceptionData.cs.  You should 
> be able to use RubyExceptionData.GetInstance to get a RubyExceptionData 
> object for the thrown exception and then access the Backtrace property 
> on this object to get the frame information.

Hm, the Backtrace property has the stack frame in question, but contains 
no useful information. Consider the following program (output is below):

ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup();
runtimeSetup.DebugMode = true;
runtimeSetup.LanguageSetups.Add(Ruby.CreateRubySetup());
ScriptRuntime runtime = new ScriptRuntime(runtimeSetup);
ScriptEngine engine = runtime.GetRubyEngine();
ScriptScope scriptScope = engine.CreateScope();
ScriptSource source = engine.CreateScriptSourceFromString(
@"
a = nil
a.blarg();
");

try
{
    source.Execute(scriptScope);
}
catch (Exception e)
{
    RubyExceptionData red = RubyExceptionData.GetInstance(e);
    Console.WriteLine("Oh no! " + e.Message);
    foreach(MutableString l in red.Backtrace)
        Console.WriteLine(l.ConvertToString());
}


- output -

Oh no! undefined method `blarg' for nil:NilClass
:0
H:\path\to\my\Program.cs:36:in `Main'

--

I might expect the second line of output (":0") to look something like 
":3". Have I missed something in my setup of all the IronRuby classes? 
I've compiled both my project and IronRuby in debug mode.

Thanks,
benjamin


-- 
Posted via http://www.ruby-forum.com/.


More information about the Ironruby-core mailing list