Exception Handling
Exception is defined as an event that occurs during the execution of a program that is unexpected by the program code. The actions to be performed in case of occurrence of an exception is not known to the program. In such a case, we create an exception object and call the exception handler code. The execution of an exception handler so that the program code does not crash is called Exception handling. Exception handling is important because it gracefully handles an unwanted event, an exception so that the program code still makes sense to the user.
CODE
EG 1 . Handling Exception
#include <iostream>
using namespace std;
int main() {
    try {
        int num1, num2;
        cout << "Enter Number 1 : ";
        cin >> num1;
        cout << "Enter Number 2 : ";
        cin >> num2;
        if (num2 == 0) throw 1;
        cout << num1 / num2 << endl;
    }
    catch(int thrownValue) {
        cout << "Attempted to divide by 0" << endl;
    }
}