1
0

zexception.h 775 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef _zexception_hpp_
  2. #define _zexception_hpp_
  3. #include <stdarg.h>
  4. #include <exception>
  5. #include <string>
  6. #define DEF_EXCEPTION(clsname)\
  7. class clsname##_exception:public std::exception\
  8. {\
  9. std::string m_what;\
  10. public:\
  11. clsname##_exception(const std::string&msg) throw():m_what(msg) { } \
  12. ~clsname##_exception() throw() { } \
  13. const char* what() const throw() { return m_what.c_str(); }\
  14. };
  15. inline const char*eformat(char*buf,const char*fmt,...)
  16. {
  17. va_list ap;
  18. va_start(ap, fmt);
  19. vsprintf(buf,fmt,ap);
  20. va_end(ap);
  21. return buf;
  22. }
  23. #define THROW_EXCEPTION(clsname,fmt,...) {\
  24. char ___fmt0[512]; \
  25. char ___buf[2048]; \
  26. sprintf(___fmt0,"[%s:%d]%s",__FILE__,__LINE__,fmt);\
  27. eformat(___buf,fmt,##__VA_ARGS__);\
  28. throw clsname##_exception(___buf);\
  29. }
  30. #endif