Throwing Exceptions

Using throw statement, Exceptions can be thrown anywhere within a code. The throw exception determines:
- A type for the exception
- Type of the result of the expressions
- The type of exception thrown

Catching And Try Exceptions

The catch and try exceptions work together. The try block followed by catch block catches any exception. We can specify the type of exception we want to catch and this is all determined by exception declaration following by the keyword catch.

try {//protected code} catch(ExceptionName e) {//code to handle ExceptionName exception}
try {//protected code} catch(...) {//code to handle any exception}

C++ Standard Exceptions

C++provides a list of standard exceptions defined in <exception> which we can use in any programs. These are arranged in a parent-child class hierarchy shown below

Handle Any Type of Exceptions (…)

To handle any type of exception, we can use three dots(…) syntax inside the catch block.:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store