Skip to content

Tracebacks & try

2 messages · Hadley Wickham, Luke Tierney

#
Hi all,

The help for traceback states:

  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 for the last error.

Is there any way to get a traceback (or something similar) for an
error raised inside a try block?

Regards,

Hadley
#
You can use a calling handler along with sys.calls, something like

     f <- function() g()
     g <- function() stop("A")

     tryCatch(withCallingHandlers(f(),
 				 error = function(e) {
 						  e$calls <- sys.calls()
 				     signalCondition(e)
 				 }),
 	     error = function(e) e)

Best,

luke
On Wed, 2 Sep 2009, Hadley Wickham wrote: