What are the Standard Exceptions in C++ ?
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
C++ defined a hierarchy of standard exceptions that are thrown at runtime whenever an abnormal condition takes place.
These exceptions are derived from std::exception class defined in the header. Since there is a common base class of all these exceptions it enables the application to catch these exceptions in a single catch statement. E.g.
catch (std::exception &e)
{
//code to handle the exception
}
Some of the standard exceptions that are built in the language are: - std::bad_alloc: thrown by operator new - std::bad_cast: as a result of dynamic_cast - std::bad_typeid: as a result of operator typeid - std::bad_exception: Whenever you want to catch all exceptions then the exception parameter in the catch block should be an ellipsis. E.g.
catch (…)
{
//this block will catch all exceptions
}
Related Articles
- What is exception in Java ? explain try and catch in Java ?
- What is the Exception Handling mechanism in C++ ? What is Try and Catch in C++ ?
- Can You write your own exeptions in Java ?
- What is Operator Overloading in C++ ?
- Explain command routing ?


