Perhaps your error-checking code is causing the program to restart when
the
error crops up. If so, it might lead to the stack error. If say, every
six
hours, something changes (I think that’s how long you said it took) and
it
causes an error, the original error is caught and the program
continues/restarts execution. If the error trapping code restarts by
calling
the methods used to start the script in the first place, it would turn
into
a stack error if it’s not done correctly.
It would be like writing something on a piece of paper. Say once this
figurative piece of paper is full, the stack error crops up. If your
program
error is equivalent to the end of a line of text on this piece of paper,
after every error, or line, the program restarts, or a new line is
started.
The problem here is that as the errors or lines of text add up on this
piece
of paper, eventually, the paper is full, and you can’t write anything
else
on it, and the StackError pops up.
Basically put, your program may be just writing line after line to this
piece of paper rather than starting with a clean sheet every time it
restarts. What you want to do is go all the way back up to the program’s
initiation, where the first line of code used to start the program is,
and
set up your error rescuing code there, that way, the error is caught
where
the program begins, and you can safely restart it because that’s where
the
program started in the first place.
This probably isn’t even proper syntax, but bear with me:
def method1() # B
#…
rescue Exception # C
# restarting code here
end
method1() # A
A is the last line where method1 is called.
B is where method1 is defined/executed
C is where you have your error catching code
Right here, its basically doing this:
A -> B -> Error pops up -> Rescued by C in the context of B -> A -> B ->
Error - > rescued by C in the context of B -> A and so on.
You want it to do this instead:
def method1 #B
#…
end
begin
method1() # A
rescue Exception #C
#… Error catching code here, maybe output to console
retry
end
this time, it’s doing this:
A -> B -> Error pops up -> Rescued and restarted by C in top - level
context -> Program restarts, executing line A in top-level context
In this one, instead of restarting in the context of B, it’s going all
the
way back to the top level of execution and restarting from there, rather
than in the context of the program’s execution code itself.
A good way to set up an error system so you know what happened and
where,
and specifically why it happened is to raise a runtime error like so and
then catch it later:
def method1
# …
rescue Exception => e
raise(“Errored in method1: #{e}”)
end
end
begin
method1()
rescue RuntimeError => e
puts e
# … what to do next
end
Hope that all made sense! =P
Hope it helps, too. From what I’ve learned you want to restart your
program from where it was started initially to avoid things building up
and
getting problematic.
From: “Jayce M.” [email protected]
Sent: Monday, February 09, 2009 6:17 PM
To: “ruby-talk ML” [email protected]
Subject: Re: Got SystemStackError exception: stack level too deep