Derived exception class for more practical error reporting (Feature #124)


Added by Arman Savran about 15 years ago. Updated about 15 years ago.


Status:Done Start date:
Priority:High Due date:
Assignee:- % Done:

0%

Category:core
Target version:-
Difficulty: Pull request:

Description

I suggest a tiny but practical enhancement, deriving cv::Exception from std::exception so that error reporting will be more practical. It will not be necessary to write additional handler for opencv every time. I put my implementation below.

CV_EXPORTS string format( const char* fmt, ... );

class CV_EXPORTS Exception : public std::exception {
public:
Exception() { code = 0; line = 0; }
Exception(int _code, const string& _err, const string& _func, const string& _file, int _line)
: code(_code), err(_err), func(_func), file(_file), line(_line) {}
Exception(const Exception& exc)
: code(exc.code), err(exc.err), func(exc.func), file(exc.file), line(exc.line) {}
Exception& operator = (const Exception& exc) {
if( this != &exc ) {
code = exc.code; err = exc.err; func = exc.func; file = exc.file; line = exc.line;
}
return *this;
}

virtual const char *what() const throw()
{
String str = format("Code: %d\nError: %s\nFunction: %s\nFile: %s\nLine: %d\n",
code, err.c_str(), func.c_str(), file.c_str(), line);
char *_msg = const_cast<char *>(msg);
strncpy(_msg, str.c_str(), max_strlen);
_msg[max_strlen-1] = '\0';
return msg;
}
static const size_t max_strlen = 1024;
char msg[max_strlen];
int code;
string err;
string func;
string file;
int line;
};

Associated revisions

Revision 09dec4e8
Added by Marina Kolpakova over 12 years ago

Merge pull request #124 from branch taka-no-me:vs8-vs9-tbb

Revision 727d4ca4
Added by Andrey Pavlenko about 11 years ago

Merge pull request #124 from ilya-lavrenov:tapi_buildPyramid

History

Updated by anonymous - about 15 years ago

done in r2694

  • Status changed from Open to Done
  • (deleted custom field) set to fixed

Also available in: Atom PDF