[Rd] calling browser on error

luke at stat.uiowa.edu luke at stat.uiowa.edu
Sat Oct 16 02:54:13 CEST 2010


On Fri, 15 Oct 2010, William Dunlap wrote:

> He said to use options(error=...) instead of
> tryCatch(error=...).  In C++ lingo, the handler
> set by options("error") is called when the exception
> is thrown while tryCatch's handler is called
> when it is caught.

withCallingHandlers is another option.

luke

>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>> -----Original Message-----
>> From: r-devel-bounces at r-project.org
>> [mailto:r-devel-bounces at r-project.org] On Behalf Of Vadim Ogranovich
>> Sent: Friday, October 15, 2010 11:45 AM
>> To: 'Joshua Ulrich'
>> Cc: r-devel at r-project.org
>> Subject: Re: [Rd] calling browser on error
>>
>> Joshua,
>>
>> I didn't know about 'recover', thank you!
>>
>> Anyway it doesn't work for me:
>>> tryCatch((function() { x <- 1; stop('ok') })(), error=recover())
>>
>> Enter a frame number, or 0 to exit
>>
>> 1: tryCatch((function() {
>>
>> Selection: 1
>> Called from: eval(expr, envir, enclos)
>> Browse[1]> x
>> Error: object 'x' not found
>> Browse[1]> Q
>>
>> Though it does work if I set options(error = recover):
>>> options(error = recover)
>>> (function() { x <- 1; stop('ok') })()
>> Error in (function() { : ok
>>
>> Enter a frame number, or 0 to exit
>>
>> 1: (function() {
>>
>> Selection: 1
>> Called from: eval(expr, envir, enclos)
>> Browse[1]> x
>> [1] 1
>> Browse[1]> Q
>>
>> I do not run the latest R so it might be the reason:
>>> version
>>                _
>> platform       i386-pc-mingw32
>> arch           i386
>> os             mingw32
>> system         i386, mingw32
>> status
>> major          2
>> minor          9.1
>> year           2009
>> month          06
>> day            26
>> svn rev        48839
>> language       R
>> version.string R version 2.9.1 (2009-06-26)
>>
>>
>> -----Original Message-----
>> From: Joshua Ulrich [mailto:josh.m.ulrich at gmail.com]
>> Sent: Friday, October 15, 2010 1:31 PM
>> To: Vadim Ogranovich
>> Cc: r-devel at r-project.org
>> Subject: Re: [Rd] calling browser on error
>>
>> I believe options(error=recover) will do what you want.
>>
>> --
>> Joshua Ulrich  |  FOSS Trading: www.fosstrading.com
>>
>>
>>
>> On Fri, Oct 15, 2010 at 1:27 PM, Vadim Ogranovich
>> <vogranovich at jumptrading.com> wrote:
>>> Dear R-developers,
>>>
>>> I am trying to figure out a way to call browser() when an
>> error occur, and naturally I want the browser() to be called
>> in the environment of the error.
>>>
>>> I tried something simple in vain:
>>>
>>>> f <- function() { x <- 1; stop('ok') }
>>>> tryCatch(f(), error=browser())
>>> Called from: tryCatch(f(), error = browser())
>>> ## if browser() was called in the local environment of f
>> then 'x' would be set, but it's not
>>> Browse[1]> x
>>> Error: object 'x' not found
>>> Browse[1]> Q
>>>
>>> Is there a way to make it work? What do people do to 'set
>> an on-error breakpoint'?
>>>
>>> Thanks,
>>> Vadim
>>>
>>>
>>> Note: This email is for the confidential use of the named
>> addressee(s) only and may contain proprietary, confidential
>> or privileged information. If you are not the intended
>> recipient, you are hereby notified that any review,
>> dissemination or copying of this email is strictly
>> prohibited, and to please notify the sender immediately and
>> destroy this email and any attachments.  Email transmission
>> cannot be guaranteed to be secure or error-free.  Jump
>> Trading, therefore, does not make any guarantees as to the
>> completeness or accuracy of this email or any attachments.
>> This email is for informational purposes only and does not
>> constitute a recommendation, offer, request or solicitation
>> of any kind to buy, sell, subscribe, redeem or perform any
>> type of transaction of a financial product.
>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> Note: This email is for the confidential use of the named
>> addressee(s) only and may contain proprietary, confidential
>> or privileged information. If you are not the intended
>> recipient, you are hereby notified that any review,
>> dissemination or copying of this email is strictly
>> prohibited, and to please notify the sender immediately and
>> destroy this email and any attachments.  Email transmission
>> cannot be guaranteed to be secure or error-free.  Jump
>> Trading, therefore, does not make any guarantees as to the
>> completeness or accuracy of this email or any attachments.
>> This email is for informational purposes only and does not
>> constitute a recommendation, offer, request or solicitation
>> of any kind to buy, sell, subscribe, redeem or perform any
>> type of transaction of a financial product.
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
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