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

The Type of a Thrown String Literal

easyExceptions

throw "disk full"; throws a string literal. Which handler runs?

📄 Code

1#include <iostream>
2#include <string>
3 
4int main() {
5 try {
6 throw "disk full";
7 } catch (const char* message) {
8 std::cout << "text: " << message << "\n";
9 } catch (const std::string& message) {
10 std::cout << "string: " << message << "\n";
11 }
12 return 0;
13}