Rethrowing Exceptions in main function - C++ Statement

C++ examples for Statement:throw

Description

Rethrowing Exceptions in main function

Demo Code

#include <iostream>
#include <stdexcept>

int main(int argc, const char *argv[]) {
    try {/*  ww  w.  j a v  a  2  s  .  c  o  m*/
        try {
            throw std::exception();
        } catch (std::exception) {
            std::cout << "Original throw caught" << std::endl;
            throw std::exception();
        }
    } catch (std::exception) {
        std::cout << "Rethrow caught" << std::endl;
    }

    return 0;
}

Result


Related Tutorials