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 7765751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:14:32+00:00 2026-06-01T15:14:32+00:00

Ryan Davis’s Ruby QuickRef says (without explanation): Don’t rescue Exception. EVER. or I will

  • 0

Ryan Davis’s Ruby QuickRef says (without explanation):

Don’t rescue Exception. EVER. or I will stab you.

Why not? What’s the right thing to do?

  • 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-01T15:14:34+00:00Added an answer on June 1, 2026 at 3:14 pm

    TL;DR: Use StandardError instead for general exception catching. When the original exception is re-raised (e.g. when rescuing to log the exception only), rescuing Exception is probably okay.


    Exception is the root of Ruby’s exception hierarchy, so when you rescue Exception you rescue from everything, including subclasses such as SyntaxError, LoadError, and Interrupt.

    Rescuing Interrupt prevents the user from using CTRLC to exit the program.

    Rescuing SignalException prevents the program from responding correctly to signals. It will be unkillable except by kill -9.

    Rescuing SyntaxError means that evals that fail will do so silently.

    All of these can be shown by running this program, and trying to CTRLC or kill it:

    loop do
      begin
        sleep 1
        eval "djsakru3924r9eiuorwju3498 += 5u84fior8u8t4ruyf8ihiure"
      rescue Exception
        puts "I refuse to fail or be stopped!"
      end
    end
    

    Rescuing from Exception isn’t even the default. Doing

    begin
      # iceberg!
    rescue
      # lifeboats
    end
    

    does not rescue from Exception, it rescues from StandardError. You should generally specify something more specific than the default StandardError, but rescuing from Exception broadens the scope rather than narrowing it, and can have catastrophic results and make bug-hunting extremely difficult.


    If you have a situation where you do want to rescue from StandardError and you need a variable with the exception, you can use this form:

    begin
      # iceberg!
    rescue => e
      # lifeboats
    end
    

    which is equivalent to:

    begin
      # iceberg!
    rescue StandardError => e
      # lifeboats
    end
    

    One of the few common cases where it’s sane to rescue from Exception is for logging/reporting purposes, in which case you should immediately re-raise the exception:

    begin
      # iceberg?
    rescue Exception => e
      # do some logging
      raise # not enough lifeboats ;)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this in Ryan Bates' railscast site, but not sure how it works.
Ryan Bates' nifty_scaffolding, for example, does this edit.html.erb <%= render :partial => 'form' %>
I heard Ryan Bates say that the Rails JavaScript helper methods prevent unobtrusive JavaScript.
I was going through Ryan Bates' video on Active Merchant integration video Railscast #145
I'm following Ryan Bate's instructions for using Omniauth to set up third party authentication,
I am following Ryan Bates railscasts I18n Internationalization and hitting a problem/question. I am
I was following along with Ryan's RailsCast Episode 339. I had installed rbenv and
I have a complicated nested form (Ryan Bates' version) with .live() attached to some
I'm new to Rails and was following Ryan Bate's tutorial on how to make
Taking Ryan Bates' asciicast as an example: http://asciicasts.com/episodes/163-self-referential-association He ends with two associations of

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.