example4_exception_handling.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <stdexcept>

void exceptionThrower() {
    throw std::runtime_error("Exception thrown!");
}

void intermediateFunction() {
    exceptionThrower();
}

int main() {
    try {
        intermediateFunction();
    } catch (const std::exception& e) {
        std::cout << "Caught exception: " << e.what() << std::endl;
    }
    return 0;
}
Back to stack_frame