What are the Standard Exceptions in C++ ?

October 28, 2007 · Filed Under C++ Questions, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

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


Get Latest JobsAdda.com Jobs, news & updates  via Email