Skip to content

Commit

Permalink
Exception: Extension to access debug information and change of line t…
Browse files Browse the repository at this point in the history
…o int type
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed May 13, 2017
1 parent 39025e4 commit d7fafbf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/Base/Exception.cpp
Expand Up @@ -80,15 +80,17 @@ void Exception::ReportException (void) const
str+= " ";
}

if(!_file.empty() && !_line.empty()) {
std::string _linestr = std::to_string(_line);

if(!_file.empty() && !_linestr.empty()) {
// strip absolute path
std::size_t pos = _file.find("src");

if (pos!=std::string::npos) {
str+="in ";
str+= _file.substr(pos);
str+= ":";
str+=_line;
str+=_linestr;
}
}

Expand Down Expand Up @@ -213,15 +215,17 @@ void FileException::ReportException (void) const
str+= " ";
}

if(!_file.empty() && !_line.empty()) {
std::string _linestr = std::to_string(_line);

if(!_file.empty() && !_linestr.empty()) {
// strip absolute path
std::size_t pos = _file.find("src");

if (pos!=std::string::npos) {
str+="in ";
str+= _file.substr(pos);
str+= ":";
str+=_line;
str+=_linestr;
}
}

Expand Down
22 changes: 20 additions & 2 deletions src/Base/Exception.h
Expand Up @@ -77,6 +77,9 @@ class BaseExport Exception : public BaseClass
// what may differ from the message given by the user in
// derived classes
inline std::string getMessage() const;
inline std::string getFile() const;
inline int getLine() const;
inline std::string getFunction() const;

/// setter methods for including debug information
/// intended to use via macro for autofilling of debugging information
Expand All @@ -97,7 +100,7 @@ class BaseExport Exception : public BaseClass
protected:
std::string _sErrMsg;
std::string _file;
std::string _line;
int _line;
std::string _function;
};

Expand Down Expand Up @@ -572,10 +575,25 @@ inline std::string Exception::getMessage() const
return _sErrMsg;
}

inline std::string Exception::getFile() const
{
return _file;
}

inline int Exception::getLine() const
{
return _line;
}

inline std::string Exception::getFunction() const
{
return _function;
}

inline void Exception::setDebugInformation(const std::string & file, const int line, const std::string & function)
{
_file = file;
_line = std::to_string(line);
_line = line;
_function = function;
}

Expand Down

0 comments on commit d7fafbf

Please sign in to comment.