[Rd] Re: [R] No traceback available when using try(...) (PR#6669)

Luke Tierney luke at stat.uiowa.edu
Sat Mar 13 14:49:15 MET 2004


On Fri, 12 Mar 2004 dmurdoch at pair.com wrote:

> On Fri, 12 Mar 2004 11:44:14 -0500, "Roger D. Peng" <rpeng at jhsph.edu>
> wrote :
> 
> >Funny, it works for me on R-patched
> >
> > > f <- function(a) { return(log(a)) }
> > > f("A")
> >Error in log(x) : Non-numeric argument to mathematical function
> > > traceback()
> >2: log(a)
> >1: f("A")
> > > try(f("A"))
> >Error in log(x) : Non-numeric argument to mathematical function
> > > traceback()
> >2: log(a)
> >1: f("A")
> 
> Oops, I get the same behaviour as you now.  I think I must have edited
> the transcript before and changed the order of the lines:  now I get
> the "no traceback" message only if the try(f("A")) comes first.  And
> notice this infelicity:
> 
> > f("A")
> Error in log(x) : Non-numeric argument to mathematical function
> > traceback()
> 2: log(a)
> 1: f("A")
> > try(f("B"))
> Error in log(x) : Non-numeric argument to mathematical function
> > traceback()
> 2: log(a)
> 1: f("A")                  # The wrong traceback!
> 
> Presumably what is happening is that the second error leaves the old
> traceback in place in both situations.  I don't think it should do
> that.  Luke says the trace is unavailable by the time the try()
> returns; could the old one be cleared at the time of the error, to
> avoid giving misleading information?

I'm not sure there aren't cases where clearing the traceback wouldn't
be more confusing.  The current situation has a simple (and I think
fairly accurate) description: traceback() prints the traceback of the
most recent uncaught error.  Since try() is used in code to catch
errors, and could be used inside code where the user is not aware that
an error was caught, all of a sudden claiming that there is no
traceback could be more confusing in some cases.

luke

-- 
Luke Tierney
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
   Actuarial Science
241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-devel mailing list