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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:44:15+00:00 2026-06-17T12:44:15+00:00

Why did the C++ standard bother inventing the std::exception classes? What’s their benefit? My

  • 0

Why did the C++ standard bother inventing the std::exception classes? What’s their benefit? My reason for asking is this:

try
{
  throw std::string("boom");
}
catch (std::string str)
{
  std::cout << str << std::endl;
}

Works fine. Later, if I need, I can just make my own lightweight “exception” types. So why should I bother with std::exception?

  • 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-17T12:44:16+00:00Added an answer on June 17, 2026 at 12:44 pm

    Why did the C++ standard bother inventing the std::exception classes? What’s their benefit?

    It provides a generic and consistent interface to handle exceptions thrown by the standard library. All the exceptions generated by the standard library are inherited from std::exception.

    Note that standard library api’s can throw a number of different kinds of exceptions, To quote a few examples:

    • std::bad_alloc
    • std::bad_cast
    • std::bad_exception
    • std::bad_typeid
    • std::logic_error
    • std::runtime_error
    • std::bad_weak_ptr | C++11
    • std::bad_function_call | C++11
    • std::ios_base::failure | C++11
    • std::bad_variant_access | C++17

    and so on…
    std::exception is the base class for all these exceptions:

    exceptions hierarchy

    providing a base class for all these exceptions, allows you to handle multiple exceptions with a common exception handler.


    If I need, I can just make my own lightweight “exception” types. So why should I bother with std::exception?

    If you need your custom exception class go ahead and make one. But std::exception makes your job easier because it already provides a lot of functionality which a good exception class should have. It provides you the ease of deriving from it and overidding necessary functions(in particular std::exception::what()) for your class functionality.
    This gives you 2 advantages the std::exception handler,

    • can catch standard library exceptions as well as
    • exceptions of the type of your custom exception class

    Image courtesy: http://en.cppreference.com/w/cpp/error/exception

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

Sidebar

Related Questions

From the standard view-based application, I found that the generated code did this: self.window.rootViewController
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
Did some googling and couldn't find a clear answer on this. My assumption is
Does the standard specify the official C++ grammar? I searched, but did not find
my program normally has a standard background: black.jpg. In the applicationDidFinishLaunching I did the
This is a very standard newbie question, but I am looking for an expert
Possible Duplicate: For nested templates, when did `>>` become standard C++ (instead of `>
I did some searching and couldn't find an answer to this, plus did some
Would I use the standard map api? The reason I ask is that I'd
I'm creating a standard 'framework' in PHP for my own projects. On this point

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.