Re: ExceptionHandler class & list of error messages ?
Hi I tried to "copy" your code (the names are a bit different) and i
get an error when i compile which i don't understand well... could you
help me a bit more please ? thank you...
/////// COMPILE ERROR
test.cpp: In member function `virtual const char* TException::what()
const':
test.cpp:28: error: passing `const std::map<const int, const char*,
std::less<const int>, std::allocator<std::pair<const int, const char*>
' as `this' argument of `_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = const int, _Tp = const char*, _Compare = std::less<const int>, _Alloc = std::allocator<std::pair<const int, const char*> >]' discards qualifiers
/////// CODE
#include <iostream>
#include <deque>
#include <map>
#include <exception>
#define PRINTERROR 0
#define ABORTERROR 1
class TException : public std::exception
{
public:
enum errorCode {
TEST1 = 1,
TEST2,
TEST3
};
typedef std::map<const int, const char*> MsgMap;
public:
TException( const int code, const int severity = PRINTERROR ) :
m_code( code ),
m_severity( severity )
{}
~TException() throw() {}
virtual const char* what() const throw()
{
return myMsgMap[ m_code ];//"some text";
}
public:
private:
const int m_severity;
const int m_code;
const static MsgMap myMsgMap;
};
namespace
{
class TInitialise
{
public:
TException::MsgMap m_;
public:
operator TException::MsgMap() const { return m_; }
TInitialise() {};
TInitialise &Add() { std::cout << "in add\n"; return *this; }
};
}
const TException::MsgMap TException::myMsgMap = TInitialise()
.Add()
.Add();
int main()
{
return 0;
}