pro*_*eek 0 c++ exception-handling
使用以下代码,我得到了"Gotcha!" 用python.
try:
x = 0
y = 3/x
except Exception:
# ZeroDivisionError
print "Gotcha!"
我认为这是等效的C++代码,但它无法捕获该异常.
#include <iostream>
int main()
{
int x = 0;
//float y = 3.0/x;
int z = 0;
try {
z = 3 / x;
} catch (std::exception) {
std::cout << "Gotcha!";
}
std::cout << z;
}
Run Code Online (Sandbox Code Playgroud)
Floating point exception
什么地方出了错?我怎么能抓住这个例外?