summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/Exception.cpp42
-rw-r--r--src/Core/Exception.h21
2 files changed, 37 insertions, 26 deletions
diff --git a/src/Core/Exception.cpp b/src/Core/Exception.cpp
index 0029613..3e9da4d 100644
--- a/src/Core/Exception.cpp
+++ b/src/Core/Exception.cpp
@@ -24,45 +24,45 @@
namespace Mad {
namespace Core {
-std::string Exception::strerror() const {
- std::string ret;
-
- if(!where.empty())
- ret = where + ": ";
+void Exception::updateWhatStr() {
+ if(where.empty())
+ whatStr.clear();
+ else
+ whatStr = where + ": ";
switch(errorCode) {
case SUCCESS:
- return ret + "Success";
+ whatStr += "Success";
case UNEXPECTED_PACKET:
- return ret + "An unexpected packet was received";
+ whatStr += "An unexpected packet was received";
case INVALID_ACTION:
- return ret + "The action is invalid";
+ whatStr += "The action is invalid";
case NOT_AVAILABLE:
- return ret + "Not available";
+ whatStr += "Not available";
case NOT_FINISHED:
- return ret + "Not finished";
+ whatStr += "Not finished";
case NOT_IMPLEMENTED:
- return ret + "Not implemented";
+ whatStr += "Not implemented";
case NOT_FOUND:
- return ret + "Not found";
+ whatStr += "Not found";
case INVALID_INPUT:
- return ret + "Invalid input";
+ whatStr += "Invalid input";
case PERMISSION:
- return ret + "Permission denied";
+ whatStr += "Permission denied";
case INTERNAL_ERRNO:
- return ret + std::strerror(subCode);
+ whatStr += std::strerror(subCode);
case INVALID_ADDRESS:
- return ret + "Invalid address";
+ whatStr += "Invalid address";
case ALREADY_IDENTIFIED:
- return ret + "The host is already identified";
+ whatStr += "The host is already identified";
case UNKNOWN_DAEMON:
- return ret + "The daemon is unknown";
+ whatStr += "The daemon is unknown";
case DUPLICATE_ENTRY:
- return ret + "Duplicate entry";
+ whatStr += "Duplicate entry";
case AUTHENTICATION:
- return ret + "Authentication failure";
+ whatStr += "Authentication failure";
default:
- return ret + "Unknown error";
+ whatStr += "Unknown error";
}
}
diff --git a/src/Core/Exception.h b/src/Core/Exception.h
index fb6fae7..f12b3df 100644
--- a/src/Core/Exception.h
+++ b/src/Core/Exception.h
@@ -22,12 +22,13 @@
#include "export.h"
+#include <exception>
#include <string>
namespace Mad {
namespace Core {
-class MAD_CORE_EXPORT Exception {
+class MAD_CORE_EXPORT Exception : public std::exception {
public:
enum ErrorCode {
SUCCESS = 0x0000, UNEXPECTED_PACKET = 0x0001, INVALID_ACTION = 0x0002, NOT_AVAILABLE = 0x0003, NOT_FINISHED = 0x0004, NOT_IMPLEMENTED = 0x0005,
@@ -46,18 +47,28 @@ class MAD_CORE_EXPORT Exception {
long subCode;
long subSubCode;
+ std::string whatStr;
+
+ void updateWhatStr();
+
public:
Exception(const std::string &where0, ErrorCode errorCode0 = SUCCESS, long subCode0 = 0, long subSubCode0 = 0)
- : where(where0), errorCode(errorCode0), subCode(subCode0), subSubCode(subSubCode0) {}
- Exception(ErrorCode errorCode0 = SUCCESS, long subCode0 = 0, long subSubCode0 = 0) : errorCode(errorCode0), subCode(subCode0), subSubCode(subSubCode0) {}
- virtual ~Exception() {}
+ : where(where0), errorCode(errorCode0), subCode(subCode0), subSubCode(subSubCode0) {
+ updateWhatStr();
+ }
+ Exception(ErrorCode errorCode0 = SUCCESS, long subCode0 = 0, long subSubCode0 = 0) : errorCode(errorCode0), subCode(subCode0), subSubCode(subSubCode0) {
+ updateWhatStr();
+ }
+ virtual ~Exception() throw () {}
const std::string& getWhere() const {return where;}
ErrorCode getErrorCode() const {return errorCode;}
long getSubCode() const {return subCode;}
long getSubSubCode() const {return subSubCode;}
- std::string strerror() const;
+ virtual const char* what() const throw () {
+ return whatStr.c_str();
+ }
operator bool() const {
return (errorCode != SUCCESS);