00001 #ifndef LIBSHERPA_UEXCEPT_H 00002 #define LIBSHERPA_UEXCEPT_H 00003 00004 /************************************************************************** 00005 * 00006 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, The EROS 00007 * Group, LLC. 00008 * Copyright (C) 2004, 2005, 2006, Johns Hopkins University. 00009 * All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or 00012 * without modification, are permitted provided that the following 00013 * conditions are met: 00014 * 00015 * - Redistributions of source code must contain the above 00016 * copyright notice, this list of conditions, and the following 00017 * disclaimer. 00018 * 00019 * - Redistributions in binary form must reproduce the above 00020 * copyright notice, this list of conditions, and the following 00021 * disclaimer in the documentation and/or other materials 00022 * provided with the distribution. 00023 * 00024 * - Neither the names of the copyright holders nor the names of any 00025 * of any contributors may be used to endorse or promote products 00026 * derived from this software without specific prior written 00027 * permission. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00030 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00031 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00032 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00033 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00034 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00035 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00036 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00037 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00038 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00039 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00040 * 00041 **************************************************************************/ 00042 00043 #include "format.hxx" 00044 00045 namespace sherpa { 00046 00053 struct UExceptionType { 00054 const std::string name; 00055 UExceptionType(const std::string& s); 00056 ~UExceptionType(); 00057 }; 00058 00059 class UExceptionBase { 00060 public: 00061 const UExceptionType *et; 00062 std::string msg; 00063 const char *file; 00064 uint32_t line; 00065 00066 UExceptionBase(const UExceptionType *et, const char *file, int line, 00067 const std::string& msg); 00068 UExceptionBase(const UExceptionBase& cme); 00069 virtual ~UExceptionBase(); 00070 }; 00071 00072 00077 template<UExceptionType *eType> 00078 class UException : public UExceptionBase { 00079 public: 00080 UException(const char *file, int line, const std::string& msg) 00081 : UExceptionBase(eType, file, line, msg) 00082 { 00083 } 00084 UException(const UException& cme) 00085 : UExceptionBase(cme) 00086 { 00087 } 00088 ~UException() 00089 { 00090 } 00091 }; 00092 00093 // Commonly used exception types 00094 namespace excpt { 00095 // Assertion failure 00096 extern UExceptionType Assert; 00097 // Out of memory 00098 extern UExceptionType OutOfMemory; 00099 // Object integrity has failed 00100 extern UExceptionType IntegrityFail; 00101 // Object violates its schema 00102 extern UExceptionType Malformed; 00103 // Inappropriate value for operation 00104 extern UExceptionType BadValue; 00105 // Non-null argument required 00106 extern UExceptionType NullArg; 00107 // Access violation 00108 extern UExceptionType NoAccess; 00109 // Object not found 00110 extern UExceptionType NoObject; 00111 // No object expected, but object exists 00112 extern UExceptionType ObjectExists; 00113 // I/O Operation was truncated 00114 extern UExceptionType Truncated; 00115 // I/O proceeded past end of object 00116 extern UExceptionType Overrun; 00117 // Some error occurred while running a subprocess. 00118 // FIX: This is too general. It needs at least an 00119 // error code and perhaps something better than that. 00120 extern UExceptionType Subprocess; 00121 // Could not acquire lock 00122 extern UExceptionType LockFail; 00123 // Lock race failed 00124 extern UExceptionType LostLock; 00125 // Heat death of universe has occurred (a cryptographic hash 00126 // collision has occurred 00127 extern UExceptionType UniverseDied; 00128 // Network connect/session setup failed 00129 extern UExceptionType NoConnect; 00130 // Unable to authenticate 00131 extern UExceptionType NoAuth; 00132 // Missing something from environment 00133 extern UExceptionType Environ; 00134 // Unknown object version 00135 extern UExceptionType VersionError; 00136 // Network connection lost 00137 extern UExceptionType ConnLost; 00138 // Unspecified error during I/O 00139 extern UExceptionType IoError; 00140 // Unknown protocol operation 00141 extern UExceptionType BadOpcode; 00142 // Some problem with the pseudo-random number generator 00143 extern UExceptionType PrngError; 00144 // Array bounds violation 00145 extern UExceptionType BoundsError; 00146 00147 // Use when you can't decide. It is *always* a mistake to use this. 00148 extern UExceptionType Unspecified; 00149 } /* namespace excpt */ 00150 00151 } /* namespace sherpa */ 00152 00153 #define THROW(ex,s) throw ::sherpa::UException<&ex>(__FILE__, __LINE__, s) 00154 00155 // Local Variables: 00156 // mode:c++ 00157 // End: 00158 00159 #endif /* LIBSHERPA_UEXCEPT_H */
1.4.7