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

  • SEARCH
  • Home
  • 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 7174773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:07:45+00:00 2026-05-28T16:07:45+00:00

Often I need to throw a custom(ized) error. Like when a resource cannot be

  • 0

Often I need to throw a custom(ized) error. Like when a resource cannot be found due to a mismatch in parameters or so.

I prefer to throw existing errors or, throw an error that is inherited from an existing error. That way, I don’t introduce Error classes that were already defined and could have been used perfectly (DRY). But it also allows to keep wording and style the same, by inheriting and simply changing a word or two to clarify the difference with the original Error.

For example:

Foo.new
Foo.some_external_id = nil
Foo.fetch_external_resource
# => InvalidOptions: Calling Foo#fetch_external_resource with nil is invalid

I am quite sure such errors are already defined. In fact, after reading trough many lines of code, I found my MongoID driver has Mongoid::Errors::InvalidOptions: Calling Document#find with nil is invalid.

Is there a list of available Error classes in Ruby Core and Ruby on Rails? Is there a way to get such a list for your current project?

Is it smart at all to re-use and/or inherit existing errors, or should I maintain my own, custom set instead?

  • 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-05-28T16:07:46+00:00Added an answer on May 28, 2026 at 4:07 pm

    There’s a mostly adequate solution here: http://www.ruby-forum.com/topic/158088

    Since this question is unanswered, yet coming up at the top of Google search results, I decided to wrap Frederick Cheung’s solution up in a rake task and post it here.

    Drop the following in lib/tasks/exceptions.rake

    namespace :exceptions do
      task :list => :environment do
        exceptions = []
    
        ObjectSpace.each_object(Class) do |k|
          exceptions << k if k.ancestors.include?(Exception)
        end
    
        puts exceptions.sort { |a,b| a.to_s <=> b.to_s }.join("\n")
      end
    end
    

    Run it with:

    bundle exec rake exceptions:list
    

    If you’re still on Rails 2, or not using Bundler, leave off the bundle exec

    This list is probably adequate, but not exhaustive. For example, ActiveResource defines several exceptions such as ActiveResource::ConnectionError and ActiveResource::TimeoutError that are not appearing when I run this task. Maybe someone else can enlighten me as to why.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have call hierarchies in that all methods need the same parameters. If
I often need to enter text (consisting of repeated characters) like this: ------------------------------------ TODO
While learning Java I stumble upon this error quite often. It goes like this:
I often need to run reduce (also called foldl / foldr, depending on your
I often need to design a dialog in Delphi/C++Builder that allows various properties of
I often need to display information based on or influenced by a user's actual
I often need to use a function which performs and action X is condition
I often need relatively small (<10000 entries <1kb) caches for speeding up calculations. My
I often need to list items with various-sized images on the left and text
I often need to fetch tgz files, decompress them, and then delete the tgz.

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.