Learning to Backtrace

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
In an effort to improve my coding habits and knowledge of Ruby I am learning how to handle errors. While using backtrace in Aptana it shows the offending filename, line number and method. However in RPG maker with the same code the file name part shows what appears to be the script index instead of the name. The RPG maker help file says that backtrace should output like so:

"#{sourcefile}:#{sourceline}:in `#{method}'"I'll use the following script as an example:

class Test def self.run(arg1) num = 5 num /= arg1 raise ZeroDivisionError, "arg1 must not equal 0 or 0.0\n" if arg1 == 0.0 return num rescue ZeroDivisionError => e print e.message e.backtrace.join("\n") endendclass Test2 def self.run2 puts Test.run(0) endendTest2.run2
This in Aptana outputs:

arg1 must not equal 0 or 0.0C:/Users/Name/Documents/Aptana Studio 3 Workspace/testing/testfile.rb:19:in `run'C:/Users/Name/Documents/Aptana Studio 3 Workspace/testing/testfile.rb:29:in `run2'C:/Users/Name/Documents/Aptana Studio 3 Workspace/testing/testfile.rb:33:in `<main>'In RPG maker it outputs as:

arg1 must not equal 0 or 0.0{0128}:19:in 'run'{0128}:29:in 'run2'{0128}:33:in '<main>'So then how can I use backtrace to output something like:

arg1 must not equal 0 or 0.0Testfile:19:in 'run'Testfile:29:in 'run2'Testfile:33:in '<main>'Thanks for any help on this. :)
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
I'm on my phone, so I'm going to keep this short, but $RGSS_SCRIPTS[id][1] I believe. Just check out the $RGSS_SCRIPTS array.
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
Thanks :D !

By the way wondering if someone could explain (or recommend a good book) on how backtrace comes up with it's information.
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
Thanks Andar for linking that, explains how it works pretty well. :)

Edit: My method is strangely simpler though (as I couldn't figure out set_backtrace for line and method calls before you posted) so I went with this :

  rescue ZeroDivisionError => e    msgbox(e.message, e.backtrace[0..e.backtrace.size-2].join("\n").gsub(    /({\d*})/i) { |id| "From: #{$RGSS_SCRIPTS[id[1..4].to_i][1]}"})Since it was already doing the line number and method call thought well might just be easy to gsub the {0128} out replace with the script name and use that number to find which scripts were causing the problem.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,081
Members
137,582
Latest member
Spartacraft
Top