读书人

try catch(exception * ex)怎么使用

发布时间: 2012-03-09 16:54:57 作者: rapoo

try catch(exception * ex)如何使用?
请问,这个怎么用?
我这么写,Dev-cpp可以编译,但是无法运行。

#include <cstdlib>
#include <iostream>

class MyExc{
public:
void f(){
std::cout < < "...\n ";
}
};

int main(int argc, char *argv[])
{
try{
throw MyExc();
}
catch(MyExc* me){
std::cout < < "Error\n ";
}
system( "PAUSE ");
return 0;
}


返回错误
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application 's support team for more information.

[解决办法]
try{
throw MyExc();
}
catch(MyExc& me){
std::cout < < "Error\n ";
}
[解决办法]
楼上可以

try{
throw MyExc();
}
catch(MyExc me){
std::cout < < "Error\n ";
}
也可

读书人网 >C++

热点推荐