单选题 适中
#20931

运行下面的代码,屏幕上将输出( )。 # include <iostream> using namespace std ; int divide ( int a…

运行下面的代码,屏幕上将输出( )。

#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;
}
未登录也能判分,登录后才会记录
答案与解析
正确答案:C
这道题暂未补解析。