如何使用非检查代码库处理OPENCV错误
我有一个非远外的GRPC服务代码基础,该代码基础使用“错误代码返回”策略来处理各种错误(当发生错误时(不是全部,仅是不可手持的),它会一直引起链条反应一直到服务响应呼叫和响应带有错误代码的客户端请求调用) 现在,我必须依靠一些第三方库(例如OpenCV),我想知道如何处理OpenCV API可能造成的潜在错误。
代码示例:
#include<opencv2/opencv/hpp>
int A(args)
{
...
int errCode = B(); //this is how i handle all my internal api call or other thrid party same error-style api calls, it returns an int error code and checked
if(errCode)
{
//log...;
//resouce release...
return errCode;
}
...
return 0; //0 means succ call
}
int B(args)
{
...
cv::OPENCV_API(cv::Mat, cv::Mat,...args). // how to handle this api call?
...
}
,这是我的问题:
1.如果OPENCV API调用出现问题会发生什么,我搜索了OpenCV错误处理,请参阅大多数人都会引发异常,因此整个服务将会流产?
- 如果我不想使用尝试{...}在我的代码中捕获{...} ?
3.例如,最糟糕的是,我必须使用 try {...}抓住{...} ,应该如何被击退?下面的某些事情会起作用吗
//int A() remains same
int B(args)
{
...
try
{
...
cv::OPENCV_API(cv::Mat, cv::Mat,...args). // how to handle this api call?
...
}
catch
{
log...;
int errCode = -1000;
return errCode;
}
return 0;
}
?以及使用局部抛弃语法的Thrid Party代码进行错误处理?
I have a non-exception grpc service code base which uses “error code return” strategy to deals with all kinds of errors(when an error happens(not all, only the unhandleable ones), it causes a chain reaction all the way to the service response call and response the client request call with an error code)
now I have to rely on some third party library (say openCV), and I'm wondering how to handle the potential errors that may caused by openCV apis.
code examples:
#include<opencv2/opencv/hpp>
int A(args)
{
...
int errCode = B(); //this is how i handle all my internal api call or other thrid party same error-style api calls, it returns an int error code and checked
if(errCode)
{
//log...;
//resouce release...
return errCode;
}
...
return 0; //0 means succ call
}
int B(args)
{
...
cv::OPENCV_API(cv::Mat, cv::Mat,...args). // how to handle this api call?
...
}
and here is my questions:
1.what will happen if something is wrong with the opencv api call, I searched opencv error handling, see that most of it throws exceptions, so the whole service will be aborted?
- if I don't want to use try {...} catch {...} in my code, how should I work with exception-throw style third party code to avlid them from crash my service?
3.say the worst, I have to use try {...} catch {...}, how should it be woked out? is some thing like below will work?(means that my service won't abort or cratch):
//int A() remains same
int B(args)
{
...
try
{
...
cv::OPENCV_API(cv::Mat, cv::Mat,...args). // how to handle this api call?
...
}
catch
{
log...;
int errCode = -1000;
return errCode;
}
return 0;
}
TL;DR if I don't use throw-exception syntax in my own code, how do I utilize and error-handling with thrid-party code that applys throw-exception syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论