#include <iostream>
int main() {
int x = 10;
int y = 0;
// 尝试除以零,这将导致运行时错误
try {
int result = x / y;
} catch (const std::exception& e) {
// 输出错误消息到 std::cerr
std::cerr << "Caught an exception: " << e.what() << std::endl;
}
// 输出一条普通消息到 std::cerr(尽管通常我们会使用 std::cout 进行这种操作)
std::cerr << "This is a message to stderr." << std::endl;
return 0;
}
【CPP】异常获取
最新推荐文章于 2024-06-07 20:11:45 发布