From luke at stat.uiowa.edu  Sat Mar 13 14:49:15 2004
From: luke at stat.uiowa.edu (Luke Tierney)
Date: Sat Mar 13 14:49:10 2004
Subject: [Rd] Re: [R] No traceback available when using try(...) (PR#6669)
In-Reply-To: <20040312203928.75CBFFB88@slim.kubism.ku.dk>
Message-ID: <Pine.LNX.4.44.0403130743170.7284-100000@itasca2.stat.uiowa.edu>

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

> On Fri, 12 Mar 2004 11:44:14 -0500, "Roger D. Peng" <rpeng@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@stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu


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