Benjamin van der Veen
2008-Dec-11 06:09 UTC
[Ironruby-core] Determining line number of runtime errors
Hello all, I''m just wondering if there''s any way to see what line of the source code was being executed when an error occurred. This is possible when the source is being parsed/compiled/interpreted by inspecting SyntaxErrorException.Line? what about when the source is being evaluated? Thanks, benjamin -- Posted via http://www.ruby-forum.com/.
Michael Letterle
2008-Dec-11 15:15 UTC
[Ironruby-core] Determining line number of runtime errors
You should be able to pass in "-D" to ir.exe to get this information. On Thu, Dec 11, 2008 at 1:09 AM, Benjamin van der Veen <lists at ruby-forum.com> wrote:> Hello all, > > I''m just wondering if there''s any way to see what line of the source > code was being executed when an error occurred. This is possible when > the source is being parsed/compiled/interpreted by inspecting > SyntaxErrorException.Line? what about when the source is being > evaluated? > > Thanks, > benjamin > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-- Michael Letterle [Polymath Prokrammer] http://blog.prokrams.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081211/49c29586/attachment.html>
Benjamin van der Veen
2008-Dec-11 19:56 UTC
[Ironruby-core] Determining line number of runtime errors
Michael Letterle wrote:> You should be able to pass in "-D" to ir.exe to get this information. >Oops, perhaps I should have been more specific about what I''m doing. I''m not actually using ir.exe, I''m creating ScriptRuntime/ScriptEngine/ScriptScope/ScriptSource in C# code. I''m wrapping the call to aScriptSource.Execute(aScriptScope) in a try-catch block. One of my catch blocks explicitly catches a SyntaxErrorException, which as I mentioned before has a Line property. I notice that runtime errors cause many different type of exceptions, so I''m speculating that there must be some other mechanism for determining what line the error occurred on. Thanks, benjamin -- Posted via http://www.ruby-forum.com/.
Jim Deville
2008-Dec-16 00:45 UTC
[Ironruby-core] Determining line number of runtime errors
Has this been answered? I don''t think it has yet. John, Tomas or Curt? -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Benjamin van der Veen Sent: Thursday, December 11, 2008 11:56 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Determining line number of runtime errors Michael Letterle wrote:> You should be able to pass in "-D" to ir.exe to get this information. >Oops, perhaps I should have been more specific about what I''m doing. I''m not actually using ir.exe, I''m creating ScriptRuntime/ScriptEngine/ScriptScope/ScriptSource in C# code. I''m wrapping the call to aScriptSource.Execute(aScriptScope) in a try-catch block. One of my catch blocks explicitly catches a SyntaxErrorException, which as I mentioned before has a Line property. I notice that runtime errors cause many different type of exceptions, so I''m speculating that there must be some other mechanism for determining what line the error occurred on. Thanks, benjamin -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Curt Hagenlocher
2008-Dec-16 05:14 UTC
[Ironruby-core] Determining line number of runtime errors
>From the hosting interface, you need to manually set RuntimeSetup.DebugMode = true when creating the ScriptRuntime.-----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Monday, December 15, 2008 4:45 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Determining line number of runtime errors Has this been answered? I don''t think it has yet. John, Tomas or Curt? -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Benjamin van der Veen Sent: Thursday, December 11, 2008 11:56 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Determining line number of runtime errors Michael Letterle wrote:> You should be able to pass in "-D" to ir.exe to get this information. >Oops, perhaps I should have been more specific about what I''m doing. I''m not actually using ir.exe, I''m creating ScriptRuntime/ScriptEngine/ScriptScope/ScriptSource in C# code. I''m wrapping the call to aScriptSource.Execute(aScriptScope) in a try-catch block. One of my catch blocks explicitly catches a SyntaxErrorException, which as I mentioned before has a Line property. I notice that runtime errors cause many different type of exceptions, so I''m speculating that there must be some other mechanism for determining what line the error occurred on. Thanks, benjamin -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Benjamin van der Veen
2008-Dec-16 08:41 UTC
[Ironruby-core] Determining line number of runtime errors
Curt Hagenlocher wrote:>>From the hosting interface, you need to manually set RuntimeSetup.DebugMode = true when creating the ScriptRuntime.I saw that option and enabled it (this is what the -D flag does in ir.exe), but I''m not sure where I get the line number when an error occurs. I haven''t had a chance to sit down to study the source of ir.exe to see how it does it, but just by browsing through intellisense and using the immediate window in VS, I couldn''t find any relevant properties (or properties of properties) on the thrown exception or any of the other objects involved (the runtime, the engine, the scope, or the source). I must be missing something. Any ideas? Thanks, benjamin -- Posted via http://www.ruby-forum.com/.
Curt Hagenlocher
2008-Dec-16 16:44 UTC
[Ironruby-core] Determining line number of runtime errors
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. -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Benjamin van der Veen Sent: Tuesday, December 16, 2008 12:42 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Determining line number of runtime errors Curt Hagenlocher wrote:>>From the hosting interface, you need to manually set RuntimeSetup.DebugMode = true when creating the ScriptRuntime.I saw that option and enabled it (this is what the -D flag does in ir.exe), but I''m not sure where I get the line number when an error occurs. I haven''t had a chance to sit down to study the source of ir.exe to see how it does it, but just by browsing through intellisense and using the immediate window in VS, I couldn''t find any relevant properties (or properties of properties) on the thrown exception or any of the other objects involved (the runtime, the engine, the scope, or the source). I must be missing something. Any ideas? Thanks, benjamin -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Benjamin van der Veen
2008-Dec-16 19:52 UTC
[Ironruby-core] Determining line number of runtime errors
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/.
Benjamin van der Veen
2009-Jan-02 05:10 UTC
[Ironruby-core] Determining line number of runtime errors
Hello all, I hate to bump posts, but here I am doing so. I find it surprising that no one knows how to determine the line numbers of runtime errors. Curt''s suggestion to investigate RubyExceptionData.GetInstance() seemed promising, but the information in it''s Backtrace property was not correct. Anyone know why this might be the case and how I could go about fixing it? Thanks, benjamin p.s.: I''m not sure if this is a mailing list as well as a message board; if this message has no context where you''re reading it, see http://www.ruby-forum.com/topic/173123 -- Posted via http://www.ruby-forum.com/.