00001 /* 00002 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00003 May be copied only for purposes and under conditions described 00004 on the Web page www.basepath.com/aup/copyright.htm. 00005 00006 The Example Files are provided "as is," without any warranty; 00007 without even the implied warranty of merchantability or fitness 00008 for a particular purpose. The author and his publisher are not 00009 responsible for any damages, direct or incidental, resulting 00010 from the use or non-use of these Example Files. 00011 00012 The Example Files may contain defects, and some contain deliberate 00013 coding mistakes that were included for educational reasons. 00014 You are responsible for determining if and how the Example Files 00015 are to be used. 00016 00017 */ 00018 #ifndef _UXERR_HPP_ 00019 #define _UXERR_HPP_ 00020 00021 #include <exception> 00022 #include <iostream> 00023 00024 #define EC_CAUGHT(e)\ 00025 ec_push(__func__, __FILE__, __LINE__, "EC_CAUGHT",\ 00026 e.get_code(), e.get_type()); 00027 00028 #define EC_EXIT(e)\ 00029 {\ 00030 EC_CAUGHT(e)\ 00031 ::exit(EXIT_FAILURE);\ 00032 } 00033 00034 #define EC__EXIT(e)\ 00035 {\ 00036 EC_CAUGHT(e)\ 00037 EC_FLUSH("EC__EXIT")\ 00038 ::_exit(EXIT_FAILURE);\ 00039 } 00040 00041 #define EC_CATCH(s)\ 00042 try { s; } catch (Error e) { EC_EXIT(e) } 00043 00044 namespace Ux { 00045 00046 /** 00047 \ingroup Ux 00048 */ 00049 class Error : public exception { 00050 protected: 00051 EC_ERRTYPE e_type; 00052 int e_code; 00053 char str[50]; 00054 public: 00055 Error(int c = 0, EC_ERRTYPE t = EC_ERRNO) 00056 : e_type(t), e_code(c) 00057 { } 00058 void set(int c, EC_ERRTYPE t = EC_ERRNO) 00059 { e_type = t; e_code = c; } 00060 EC_ERRTYPE get_type(void) const 00061 { return e_type; } 00062 int get_code(void) const 00063 { return e_code; } 00064 operator int() const 00065 { return e_code; } 00066 operator const char*() const 00067 { return what(); } 00068 virtual const char *what() const throw(); 00069 }; 00070 00071 //@{ 00072 /** \name ostream Operators 00073 Operator to display Error. 00074 */ 00075 std::ostream& operator<<(std::ostream& s, const Error& e); 00076 //@} 00077 00078 } // namespace 00079 00080 #endif // _UXERR_HPP_