我的宝贝朋友;为什么它不能在C++中捕捉异常?
为什么C++在这个例子中无法捕捉到异常?你能解释我们吗?我尝试了很多,但仍然不能。如果我在cmd中输入一个char,catch块不起作用。
try {
int dX = 0;
cin >> dX;
dX = static_cast<double>(10/dX);
cout << dX << endl;
}
catch (conts std::exception &exp) { // if I input any of chars, it doesn't catch?
cerr << "Error: " << exp->what() << endl;
}
'的std :: istream'不上输入无效抛出异常,除非你明确告诉它这样做。 –
一个也不会捕获指向异常的指针,而是一个引用。 –
只需在@ BaummitAugen的(正确)声明 - [这里](http://archive.oreilly.com/pub/a/network/2003/05/05/cpluspocketref.html)中添加一个基本原理参考。 –