← Back to Question List
C++ Code Walkthrough #106
A Throw Climbs Out of a Function
📄 Code
Read carefully — what does this print?1#include <iostream>2#include <stdexcept>34void checkTemperature(int degrees) {5 std::cout << "checking " << degrees << "\n";6 if (degrees > 100) {7 throw std::runtime_error("too hot");8 }9 std::cout << "temperature ok\n";10}1112int main() {13 try {14 checkTemperature(40);15 checkTemperature(150);16 std::cout << "after both checks\n";17 } catch (const std::runtime_error& e) {18 std::cout << "stopped: " << e.what() << "\n";19 }20 std::cout << "end of main\n";21 return 0;22}