Skip to main content

Exception Handling in C++


 #include<bits/stdc++.h>

using namespace std;

int main()
{
    int x = -1;
    try{
        cout<<"Insider try\n";
        if(x<0){
            throw x;
            cout<<"After throw \n";
        }
    }
    catch(int x){
        cout<<"Exception caught\n";
    }
    cout<<"After caught";
    return 0;
}


Comments