00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef UTILITIESEXCEPTIONS_H
00022 #define UTILITIESEXCEPTIONS_H
00023
00024 #include <exception>
00025 #include <cstring>
00026 #include <cstdio>
00027 #include "baseexception.h"
00028 #include "utilitiesconfig.h"
00029
00030
00031
00032 #if defined(_MSC_VER)
00033 #pragma warning(push)
00034 #pragma warning(disable:4996)
00035 #endif
00036
00037 namespace farsa {
00038
00039
00040
00041
00042
00052 class FARSA_UTIL_TEMPLATE RuntimeUserException : public BaseException
00053 {
00054 public:
00062 RuntimeUserException(const char* reason) throw() :
00063 BaseException()
00064 {
00065 strncpy(m_reason, reason, 256);
00066 m_reason[255] = '\0';
00067 sprintf(m_errorMessage, "Generic runtime exception, reason: %s", m_reason);
00068 m_errorMessage[511] = '\0';
00069 }
00070
00076 RuntimeUserException(const RuntimeUserException& other) throw() :
00077 BaseException(other)
00078 {
00079 strncpy(m_reason, other.m_reason, 256);
00080 m_reason[255] = '\0';
00081 strncpy(m_errorMessage, other.m_errorMessage, 512);
00082 m_errorMessage[511] = '\0';
00083 }
00084
00090 RuntimeUserException& operator=(const RuntimeUserException& other) throw()
00091 {
00092 if (&other == this) {
00093 return *this;
00094 }
00095
00096 BaseException::operator=(other);
00097 strncpy(m_reason, other.m_reason, 256);
00098 m_reason[255] = '\0';
00099 strncpy(m_errorMessage, other.m_errorMessage, 512);
00100 m_errorMessage[512] = '\0';
00101
00102 return *this;
00103 }
00104
00108 virtual ~RuntimeUserException() throw()
00109 {
00110 }
00111
00117 virtual const char *what() const throw()
00118 {
00119 return m_errorMessage;
00120 }
00121
00127 const char *reason() const throw()
00128 {
00129 return m_reason;
00130 }
00131
00136 EXCEPTION_HELPER_FUNCTIONS(RuntimeUserException)
00137
00138 private:
00142 char m_reason[256];
00143
00147 char m_errorMessage[512];
00148 };
00149
00157 inline void FARSA_UTIL_TEMPLATE throwUserRuntimeError(QString reason)
00158 {
00159 throw RuntimeUserException(reason.toAscii().data());
00160 }
00161
00162 }
00163
00164
00165 #if defined(_MSC_VER)
00166 #pragma warning(pop)
00167 #endif
00168
00169 #endif