Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A way to handle runtime errors (like division by zero or file not found) gracefully without crashing the entire program.
try {
if (b == 0) throw "DivByZero";
cout << a / b;
} catch (const char* msg) {
cerr << "Error: " << msg;
}tryBlock of code where exceptions might occur.
throwUsed to signal that an error has happened.
catchBlock of code that handles the specific exception.
C++ provides a set of standard exceptions in the <stdexcept> header, like std::runtime_error and std::out_of_range.