Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7803019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:26:14+00:00 2026-06-02T01:26:14+00:00

I have a function: buggy <- function(…) { tryCatch({ itWorked <- FALSE stop(I don’t

  • 0

I have a function:

buggy <- function(...) {
    tryCatch({
        itWorked <- FALSE
        stop("I don't like green eggs and ham!")
        itWorked <- TRUE
    }, finally = {
        if ( itWorked )
            return("I do, Sam I am")
        else
            return("I do not like them, Sam I am!")
    })
}

Basically, buggy tries to do some calculations that may or may not succeed (determined by itWorked. The finally clause just makes sure that even if the calculation didn’t work, something gets returned (in this case, "I do not like them, Sam I am!").

It works as expected:

> buggy()
Error in tryCatchList(expr, classes, parentenv, handlers) : 
  I don't like green eggs and ham!
[1] "I do not like them, Sam I am!"

Now I want to listen for errors in buggy():

tryCatch( buggy(), 
          error=function(e) message('too bad! there was an error') )

However the error in buggy fails to raise an error in the surrounding tryCatch:

> tryCatch( buggy(), 
+           error=function(e) message('too bad! there was an error') )
[1] "I do not like them, Sam I am!"

I would expect this to say:

'too bad! there was an error'
[1] "I do not like them, Sam I am!"

Can anyone tell me why this does not work? Do I somehow need to ‘raise’ errors from within buggy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:26:15+00:00Added an answer on June 2, 2026 at 1:26 am

    The outer tryCatch() doesn’t give you the message stored in its error argument for exactly the same reason that the following call does not:

    tryCatch("I do not like them, Sam I am!",
        error=function(e) message('too bad! there was an error') )
    # [1] "I do not like them, Sam I am!"
    

    The message in the error argument two lines up would only be invoked if buggy() returned an error. But instead (thanks to the work of the tryCatch() inside of it), buggy() just returns a character vector, and tryCatch() has nothing to ‘catch’:

    value <- buggy()
    value
    # [1] "I do not like them, Sam I am!"
    
    # And, to belabor the point:
    identical(buggy(), "I do not like them, Sam I am!")  
    # [1] TRUE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment
i have function like this. function load($name, $arg1, $arg2, $arg3, $arg4){ $this->$name = new
I have function like this : CREATE OR REPLACE FUNCTION f_insert_account(usernames character varying, passwds
I have function like this typedef vector<vector<string> > vecArray; vecArray dul(); vecArray dul() {
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
I have function getCartItems in cart.js and I want to call that function in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have function some_func_1 which will create an object of type some_type and will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.