Commit a68c0796 authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In ElementaryUtils (trunk) :
- Correct memory allocation in CustomException what() implementation.
parent babec0ec
......@@ -22,8 +22,8 @@ public:
CustomException(const std::string &className, const std::string &funcName,
const std::string &errorMsg) throw ();
virtual ~CustomException() throw ();
CustomException (const CustomException& other) throw ();
CustomException& operator= (const CustomException& other) throw ();
CustomException(const CustomException& other) throw ();
CustomException& operator=(const CustomException& other) throw ();
virtual const char* what() const throw ();
......@@ -35,6 +35,8 @@ private:
std::string m_className;
std::string m_funcName;
std::string m_errorMsg;
std::string m_finalExceptionMsg;
};
} /* namespace ElemUtils */
......
#include "../../../include/ElementaryUtils/logger/CustomException.h"
#include <cstring>
#include "../../../include/ElementaryUtils/string_utils/Formatter.h"
#include "../../../include/ElementaryUtils/string_utils/StringUtils.h"
namespace ElemUtils {
CustomException::CustomException(const std::string &className,
const std::string &funcName, const std::string &errorMsg) throw () :
std::runtime_error(errorMsg), m_className(className), m_funcName(
funcName), m_errorMsg(errorMsg) {
std::runtime_error(m_errorMsg), m_className(className), m_funcName(
funcName), m_errorMsg(errorMsg), m_finalExceptionMsg(
StringUtils::EMPTY) {
}
CustomException::~CustomException() throw () {
......@@ -21,6 +21,7 @@ CustomException::CustomException(const CustomException& other) throw () :
m_className = other.m_className;
m_funcName = other.m_funcName;
m_errorMsg = other.m_errorMsg;
m_finalExceptionMsg = other.m_finalExceptionMsg;
}
CustomException& CustomException::operator =(
......@@ -28,15 +29,15 @@ CustomException& CustomException::operator =(
m_className = other.m_className;
m_funcName = other.m_funcName;
m_errorMsg = other.m_errorMsg;
m_finalExceptionMsg = other.m_finalExceptionMsg;
return *this;
}
const char* CustomException::what() const throw () {
ElemUtils::Formatter formatter;
formatter << "(" << m_className << "::" << m_funcName << ") " << m_errorMsg;
char * cstr = new char [formatter.str().length()+1];
std::strcpy (cstr, formatter.str().c_str());
return cstr;
m_finalExceptionMsg = Formatter() << "(" << m_className << "::"
<< m_funcName << ") " << m_errorMsg;
return m_finalExceptionMsg.c_str();
}
const std::string& CustomException::getClassName() const {
......
Supports Markdown
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