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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:54:22+00:00 2026-06-06T16:54:22+00:00

According to this site it is perfectly usable to throw a string or integer.

  • 0

According to this site it is perfectly usable to throw a string or integer. I find this to be pretty clean and easy to understand. What are the downsides to throw "description of what happened" rather than throw std::runtime_error("description of what happened")?

  • 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-06T16:54:23+00:00Added an answer on June 6, 2026 at 4:54 pm

    That site is stupid, and teaches bad design.

    If you throw int or char*, then you will have to catch it using int or char* only. You may qualify it with const.

    If you throw std::runtime_error, then you can catch it using std::runtime_error const &, or its base class std::exception const &.

    So what is good about it?

    The good about it is that if you throw an exception using a class which is ultimately derived from std::exception, then you can write just ONE catch block which accepts the exception as std::exception const&, irrespective of which derived class is used to throw exception.

    Here is one example:

    void f(A & a)
    {
        if ( !check_arg(a) )
        {
              throw std::invalid_argument("invalid argument");
        }
        else if ( !check_size(a) )
        {
              throw std::length_error("invalid length");            
        }
    
        //code
        if(someCondition)
        {
              //assume your_own_defined_exception's ultimate base is std::exception
              throw your_own_defined_exception("condition unsatisfied");                         
        }
        //...
    
    }
    

    Now the interesting part:

    try
    {
          f(a); //it can throw exception of at least 3 types!
    }
    catch(std::exception const &e) //all types can be caught by just one catch!
    {
         //handle this case
    }
    

    The good is that you are not required to write three catch blocks just because f() could throw three different types of exception. You may write more than one catch to handle them differently if that benefits you in some way. But the point to be noted here is: that is not a requirement!

    In short, you can take advantage of the class hierarchy.

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

Sidebar

Related Questions

According this article , generic JPA DAO(Data Access Object) is a pretty nice pattern.
I didnt find anything according this issue. Can jaas be used to secure my
according to this site http://www.cplusplus.com/reference/std/functional/unary_function/ this code should work #include <iostream> #include <functional> using
According to this calculator site ( link text ), when converting 3 from decimal
According to this site I can simply write $user = getlogin(); but the group
According to this site: http://httpd.apache.org/docs/2.2/howto/access.html I need to use something like the script below
I am trying to get a multilingual site up according to this tutorial: http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/
According to this site the ordering algorithm for hacker news goes something like this:
According to Herb Sutter the code below wouldn't compile. See this site http://www.gotw.ca/gotw/066.htm from
According to this site http://www.searchable-pdf.com/content.php?lang=en&c=61 , a PDF can be searchable when a text

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.