void test_try()
{
cv::Mat img = cv::Mat::zeros(3, 3, CV_8UC1);//在release下,OpenCV默认会关闭这些调试功能,以提高性能和减少内存占用
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
uchar a= img.at<uchar>(i, j);
}
}
std::vector<int>v;
v.push_back(1);
v.clear();
std::cout << "vv=" << v.at(2);//捕获数组越界异常,可以使用at()函数而不是使用下标访问。
}
void test34()
{
try
{
test_try();
}
catch (const cv::Exception& e)
{
std::cout << "e.what() "<<e.what() << std::endl;
std::cout << "e.file " << e.file << std::endl;
std::cout << "e.code " << e.code << std::endl;
std::cout << "e.err " << e.err << std::endl;
std::cout << "e.line " << e.line << std::endl;
std::cout << "e.func " << e.func << std::endl;
std::cout << "e.msg " << e.msg << std::endl;
}
catch (const std::exception& e2)
{
std::cout << e2.what() << std::endl;
}
}
try catch 捕获异常
最新推荐文章于 2024-08-17 23:59:05 发布