A31073. 运行下面的代码,屏幕上将输出( )。#include <iostream>using namespace std;int divide(int a, int b) { if (b == 0) { throw runtime_error("division by zero error "); } return a / b;}int main() { int x = 10; int y = 0; /…
单选题
较难
知识点
题目描述
运行下面的代码,屏幕上将输出( )。
#include <iostream>
using namespace std;
int divide(int a, int b) {
if (b == 0) {
throw runtime_error("division by zero error ");
}
return a / b;
}
int main() {
int x = 10;
int y = 0; // 设为 0 会导致除零错误
try {
int result = divide(x, y);
cout << "result: " << result << endl;
} catch (const runtime_error& e) {
cout << "caught an exception: " << e.what() << endl;
}
return 0;
}
选项(单选)
答案解析
详细答案解析为会员权益,按每日次数查看。
开通 / 升级会员
上一题
下一题