C++ 异常处理

详细介绍可参看CSDN官方介绍,链接地址 http://msdn.microsoft.com/zh-cn/library/hh279678.aspx

 以下是应用中的实例:

 1     
 2 #include <stdexcept>//异常处理库
 3 
 4 //内参数矩阵mK求逆,并打印显示其逆矩阵
 5     try    //异常处理 针对K为奇异矩阵不可逆的情况
 6     {
 7         if (invert(mK,mInvK,cv::DECOMP_LU))    //矩阵求逆,如果矩阵为奇异矩阵,条件不成立
 8         {
 9             std::cout << mInvK << std::endl;//打印显示矩阵数据
10         }
11         else    //K为奇异矩阵
12         {
13             throw std::invalid_argument("Error:Intrinsic parameter K is singular.");
14                 //抛出异常“K为奇异矩阵”
15         }
16     }
17     catch(std::invalid_argument& e)    //获取异常情况
18     {
19         std::cerr << e.what() << std::endl;    //打印异常提醒
20         return -1;
21     }

 

posted @ 2014-09-06 08:58  Eastern Sunrise  阅读(208)  评论(0编辑  收藏  举报