CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #161

A Throw Inside a catch Block

hardExceptions

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>
4 
5void 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}
14 
15int 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}