Commit cd029345 authored by Vitaliy Lyudvichenko's avatar Vitaliy Lyudvichenko

Avoid throwing glog exeptions from destructor

parent 662fc9c7
...@@ -375,7 +375,15 @@ Ptr<Importer> cv::dnn::createCaffeImporter(const String&, const String&) ...@@ -375,7 +375,15 @@ Ptr<Importer> cv::dnn::createCaffeImporter(const String&, const String&)
Net cv::dnn::readNetFromCaffe(const String &prototxt, const String &caffeModel /*= String()*/) Net cv::dnn::readNetFromCaffe(const String &prototxt, const String &caffeModel /*= String()*/)
{ {
Ptr<Importer> caffeImporter = createCaffeImporter(prototxt, caffeModel); Ptr<Importer> caffeImporter;
try
{
caffeImporter = createCaffeImporter(prototxt, caffeModel);
}
catch(...)
{
}
Net net; Net net;
if (caffeImporter) if (caffeImporter)
caffeImporter->populateNet(net); caffeImporter->populateNet(net);
......
...@@ -46,52 +46,59 @@ ...@@ -46,52 +46,59 @@
#include <sstream> #include <sstream>
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#define CHECK(cond) cv::GLogWrapper(__FILE__, CV_Func, __LINE__, "CHECK", #cond, cond) #define CHECK(cond) for(cv::dnn::GLogWrapper _logger(__FILE__, CV_Func, __LINE__, "CHECK", #cond, cond); _logger.exit(); _logger.check()) _logger.stream()
#define CHECK_EQ(a, b) cv::GLogWrapper(__FILE__, CV_Func, __LINE__, "CHECK", #a"="#b, ((a) == (b))) #define CHECK_EQ(a, b) for(cv::dnn::GLogWrapper _logger(__FILE__, CV_Func, __LINE__, "CHECK", #a"="#b, ((a) == (b))); _logger.exit(); _logger.check()) _logger.stream()
#define LOG(TYPE) cv::GLogWrapper(__FILE__, CV_Func, __LINE__, #TYPE) #define LOG(TYPE) for(cv::dnn::GLogWrapper _logger(__FILE__, CV_Func, __LINE__, #TYPE); _logger.exit(); _logger.check()) _logger.stream()
namespace cv namespace cv
{ {
namespace dnn
{
class GLogWrapper class GLogWrapper
{ {
std::stringstream stream;
const char *file, *func, *type, *cond_str; const char *file, *func, *type, *cond_str;
int line; int line;
bool cond_staus; bool cond_staus, exit_loop;
std::stringstream sstream;
public: public:
GLogWrapper(const char *_file, const char *_func, int _line, GLogWrapper(const char *_file, const char *_func, int _line,
const char *_type, const char *_type,
const char *_cond_str = NULL, bool _cond_status = true const char *_cond_str = NULL, bool _cond_status = true
) : ) :
file(_file), func(_func), type(_type), cond_str(_cond_str), file(_file), func(_func), type(_type), cond_str(_cond_str),
line(_line), cond_staus(_cond_status) {} line(_line), cond_staus(_cond_status), exit_loop(true) {}
std::iostream &stream()
{
return sstream;
}
template<typename T> bool exit()
GLogWrapper &operator<<(const T &v)
{ {
if (!cond_str || cond_str && !cond_staus) return exit_loop;
stream << v;
return *this;
} }
~GLogWrapper() void check()
{ {
exit_loop = false;
if (cond_str && !cond_staus) if (cond_str && !cond_staus)
{ {
cv::error(cv::Error::StsError, "FAILED: " + String(cond_str) + "." + stream.str(), func, file, line); cv::error(cv::Error::StsError, "FAILED: " + String(cond_str) + ". " + sstream.str(), func, file, line);
} }
else if (!cond_str && strcmp(type, "CHECK")) else if (!cond_str && strcmp(type, "CHECK"))
{ {
if (!std::strcmp(type, "INFO")) if (!std::strcmp(type, "INFO"))
std::cout << stream.str() << std::endl; std::cout << sstream.str() << std::endl;
else else
std::cerr << stream.str() << std::endl; std::cerr << sstream.str() << std::endl;
} }
} }
}; };
}
} }
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment