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&)
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;
if (caffeImporter)
caffeImporter->populateNet(net);
......
......@@ -46,52 +46,59 @@
#include <sstream>
#include <opencv2/core.hpp>
#define CHECK(cond) cv::GLogWrapper(__FILE__, CV_Func, __LINE__, "CHECK", #cond, cond)
#define CHECK_EQ(a, b) cv::GLogWrapper(__FILE__, CV_Func, __LINE__, "CHECK", #a"="#b, ((a) == (b)))
#define LOG(TYPE) cv::GLogWrapper(__FILE__, CV_Func, __LINE__, #TYPE)
#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) for(cv::dnn::GLogWrapper _logger(__FILE__, CV_Func, __LINE__, "CHECK", #a"="#b, ((a) == (b))); _logger.exit(); _logger.check()) _logger.stream()
#define LOG(TYPE) for(cv::dnn::GLogWrapper _logger(__FILE__, CV_Func, __LINE__, #TYPE); _logger.exit(); _logger.check()) _logger.stream()
namespace cv
{
namespace dnn
{
class GLogWrapper
{
std::stringstream stream;
const char *file, *func, *type, *cond_str;
int line;
bool cond_staus;
bool cond_staus, exit_loop;
std::stringstream sstream;
public:
GLogWrapper(const char *_file, const char *_func, int _line,
const char *_type,
const char *_cond_str = NULL, bool _cond_status = true
) :
file(_file), func(_func), type(_type), cond_str(_cond_str),
line(_line), cond_staus(_cond_status) {}
const char *_type,
const char *_cond_str = NULL, bool _cond_status = true
) :
file(_file), func(_func), type(_type), cond_str(_cond_str),
line(_line), cond_staus(_cond_status), exit_loop(true) {}
std::iostream &stream()
{
return sstream;
}
template<typename T>
GLogWrapper &operator<<(const T &v)
bool exit()
{
if (!cond_str || cond_str && !cond_staus)
stream << v;
return *this;
return exit_loop;
}
~GLogWrapper()
void check()
{
exit_loop = false;
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"))
{
if (!std::strcmp(type, "INFO"))
std::cout << stream.str() << std::endl;
std::cout << sstream.str() << std::endl;
else
std::cerr << stream.str() << std::endl;
std::cerr << sstream.str() << std::endl;
}
}
};
}
}
#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