Nested Try Catch statements and Rethrowing Exceptions





This video tutorial explains about how to nest try and catch blocks in c++ programming.
You are gonna learn how we can nest try and catch statements, how the exception will be passes from inner or nested block to outer block, how to re throw the exception using throw in detail with example.

source code for this tutorial

#include <iostream>
#include <stdexcept>

using namespace std;

int main()
{
    try{
        try{
            throw "a character exception";
        }catch(const char *e){
             cout << "character type in inner block --> "<<e<<endl;
             cout << "rethrowing the exception"<<endl;
                throw runtime_error("sgdsdg");
        }

    }catch(const char *e){
    cout << "character type in outer block --> "<<e<<endl;
    }
    catch(...){
    cout << "unexpected exception in outer block --> "<<endl;
    }

    return 0;
}

 
Back To Top