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 #156

A noexcept Function That Throws Anyway

hardExceptions

report() is marked noexcept but throws. The program compiles (the compiler only warns). What happens when it runs?

📄 Code

1#include <iostream>
2#include <stdexcept>
3 
4void report() noexcept {
5 throw std::runtime_error("printer offline");
6}
7 
8int main() {
9 try {
10 report();
11 } catch (const std::exception& e) {
12 std::cout << "caught: " << e.what() << "\n";
13 }
14 return 0;
15}