From Kurt.Hornik at wu-wien.ac.at  Thu Sep  8 08:42:46 2005
From: Kurt.Hornik at wu-wien.ac.at (Kurt Hornik)
Date: Thu, 8 Sep 2005 08:42:46 +0200
Subject: [Rd] Tracebacks with tryCatch() and withCallingHandlers()?
In-Reply-To: <431F1FFD.7080700@maths.lth.se>
References: <431F1FFD.7080700@maths.lth.se>
Message-ID: <17183.56678.727845.312867@mithrandir.hornik.net>

>>>>> Henrik Bengtsson writes:

> When batch processing analysis, I use tryCatch() for failure handling 
> and to prevent unwanted interrupts.  I write detailed progress to log 
> file and conditions (warnings and errors) are written to the same log 
> file immediately by using withCallingHandlers(..., condition=function(c) 
> cat(c, file=logFile)).  However, I would also like to write the call 
> stack to the log file to further simplify troubleshooting;  traceback() 
> does unfortunately not work here. From ?traceback, we have

>   "Errors which are caught _via_ 'try' or 'tryCatch' do not generate a 
> traceback, so what is printed is the call sequence for the last uncaught 
> error, and not necessarily the last error."

> (and it seems to be case for withCallingHandlers() too).  Does anyone 
> know of a workaround for this?   Is there a way to get the call stack 
> within the condition handler?

tools:::.try_quietly() tries doing something similar (catch errors and
print a traceback) [the code is not necessarily a thing of beauty ...].

Hth

Best
-k



[Rd] Tracebacks with tryCatch() and withCallingHandlers()?
Kurt Hornik