www.pudn.com > dstile-0.2.rar > exceptions.h
#define IMPLEMENT_EXCEPTION(name) \
public:\
name() {\
}\
\
name(char* format, ...) {\
char tmp[1024];\
va_list va;\
\
va_start(va, format);\
vsnprintf(tmp, sizeof(tmp), format, va);\
va_end(va);\
m_class = #name;\
m_errorMsg = tmp;\
}\
protected:
class Exception {
IMPLEMENT_EXCEPTION(Exception);
public:
void Print() {
fprintf(stderr, "%s: %s\n", m_class.c_str(), m_errorMsg.c_str());
}
protected:
string m_class;
string m_errorMsg;
};
class InvalidInput : public Exception {
IMPLEMENT_EXCEPTION(InvalidInput);
};
class SystemException : public Exception {
IMPLEMENT_EXCEPTION(SystemException);
};
class GDALException : public Exception {
IMPLEMENT_EXCEPTION(GDALException);
};
inline string ErrnoToString(const int e) {
// char tmp[1024];
// if (strerror_r(e, tmp, sizeof(tmp))) snprintf(tmp, sizeof(tmp), "strerror_r failed for error code %d", e);
return string(strerror(e));
}