← Back to Question List
C++ Quiz #161
A Throw Inside a catch Block
The handler inside convert prints a line and then throws a NEW std::runtime_error. What is printed?
📄 Code
1#include <iostream>2#include <stdexcept>3#include <string>45void convert(const std::string& text) {6 try {7 int value = std::stoi(text);8 std::cout << "value " << value << "\n";9 } catch (const std::invalid_argument&) {10 std::cout << "cannot read " << text << "\n";11 throw std::runtime_error("bad record: " + text);12 }13}1415int main() {16 try {17 convert("12");18 convert("x9");19 convert("34");20 } catch (const std::runtime_error& e) {21 std::cout << "stopped: " << e.what() << "\n";22 }23 std::cout << "end\n";24 return 0;25}