关于VC中的错误处理

include <exception>

try

{}

cache(exception &e)

{

   cout<<e.what()<<endl; 

}     但是使用这个要非常注意才行,必须把 c/c++-->代码生成-->启用C++错误,改成 /eha才行

而且据说,也不是任意错误都能处理的,我就比较崩溃了;

  1. nclude <iostream>  
  2. #include <exception>  
  3. using namespace std;  
  4.   
  5. //可以自己定义Exception  
  6. class myexception: public exception  
  7. {  
  8.     virtual const char* what() const throw()  
  9.     {  
  10.         return "My exception happened";  
  11.     }  
  12. }myex;  
  13.   
  14. int main () {  
  15.     try  
  16.     {      
  17.         if(true)    //如果,则抛出异常;  
  18.             throw myex;  
  19.     }  
  20.     catch (exception& e)  
  21.     {  
  22.         cout << e.what() << endl;  
  23.     }  
  24.     return 0;  
  25. }  
  1. #include <iostream>  
  2. #include <exception>  
  3. using namespace std;  
  4. int main () {  
  5.     try  
  6.     {  
  7.         throw 1;  
  8.         throw "error";  
  9.     }  
  10.     catch(char *str)  
  11.     {  
  12.         cout << str << endl;  
  13.     }  
  14.     catch(int i)  
  15.     {  
  16.         cout << i << endl;  
  17.     }  
  18. }  

 c++ try{}catch(...){}能不能捕获所有异常

编译器vc2010 debug版本
已经在网上找了异常方面的
已经修改c++异常配置 
属性页--c/c++ --代码生成--启用c++异常-- 是,但有 SEH 异常 (/EHa)
可以把
try
{
cout<<strstr("sdfdfsdf",";");
}
catch(...){cout<<"捕获错误了";}
这个错误捕获
原文地址:https://www.cnblogs.com/davytitan/p/3268149.html