stdexcept
int main() {
// Create an array of size 5
int arr[] = {1, 2, 3, 4, 5};
try {
// Attempt to access an index out of bounds
int value = arr[5];
std::cout << "Value at index 5: " << value << std::endl;
} catch (std::out_of_range& e) {
std::cout << "Exception: " << e.what() << std::endl;
}
return 0;
}int main() {
try {
// Open a file that does not exist
std::ifstream file("non_existing_file.txt");
} catch (std::ifstream::failure& e) {
std::cout << "Exception: " << e.what() << std::endl;
}
return 0;
}