gpt4 book ai didi

c++ - 如何在 XCode 3.2.3 上启用异常处理?

转载 作者:行者123 更新时间:2023-11-30 03:08:39 26 4
gpt4 key购买 nike

如何在 XCode 中启用异常 - 3.2.3。有没有像我应该为编译器启用异常处理的标志?尝试使用谷歌搜索,但没有找到关于使用 C++ 的 XCode 的足够信息!

#include <iostream>
#include <exception>

int main()
{
try
{
int i=5,j=0;
int res = i/j;
}
catch (const std::exception& exe)
{
std::cerr<< exe.what();
}
catch (...)
{
std::cout<< "\n Default Exception Handler \n";
}

return 0;
}

输出:

Loading program into debugger…
Program loaded.
run
[Switching to process 1332]
Running…
Program received signal: “EXC_ARITHMETIC”.
sharedlibrary apply-load-rules all
kill
Current language: auto; currently c++
quit
The Debugger has exited with status 0.(gdb)

编辑:虽然原因似乎有所不同,但对任何人来说,这个数字将来可能会有帮助。

最佳答案

除以零不会引发 C++ 异常。参见 this question .

关于c++ - 如何在 XCode 3.2.3 上启用异常处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4762048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com