1 /******************************************************************************** 2 * * 3 * E x c e p t i o n T y p e s * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 2000,2020 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU Lesser General Public License as published by * 10 * the Free Software Foundation; either version 3 of the License, or * 11 * (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this program. If not, see <http://www.gnu.org/licenses/> * 20 ********************************************************************************/ 21 #ifndef FXEXCEPTION_H 22 #define FXEXCEPTION_H 23 24 namespace FX { 25 26 27 /** 28 * Generic catch-all exception. 29 * An optional message may be passed in the constructor, which must be a string 30 * literal constant. 31 */ 32 class FXAPI FXException { 33 private: 34 const FXchar *message; 35 private: 36 static const FXchar exceptionName[]; 37 public: FXException()38 FXException():message(FXException::exceptionName){} FXException(const FXchar * msg)39 FXException(const FXchar *msg):message(msg){} what()40 const FXchar *what() const { return message; } ~FXException()41 ~FXException(){} 42 }; 43 44 45 /** 46 * Fatal error exception. 47 */ 48 class FXAPI FXFatalException : public FXException { 49 private: 50 static const FXchar exceptionName[]; 51 public: FXFatalException()52 FXFatalException():FXException(FXFatalException::exceptionName){} FXFatalException(const FXchar * msg)53 FXFatalException(const FXchar *msg):FXException(msg){} 54 }; 55 56 57 /** 58 * Generic error exception. 59 */ 60 class FXAPI FXErrorException : public FXException { 61 private: 62 static const FXchar exceptionName[]; 63 public: FXErrorException()64 FXErrorException():FXException(FXErrorException::exceptionName){} FXErrorException(const FXchar * msg)65 FXErrorException(const FXchar *msg):FXException(msg){} 66 }; 67 68 69 /** 70 * Index out of range. 71 */ 72 class FXAPI FXRangeException : public FXErrorException { 73 private: 74 static const FXchar exceptionName[]; 75 public: FXRangeException()76 FXRangeException():FXErrorException(FXRangeException::exceptionName){} FXRangeException(const FXchar * msg)77 FXRangeException(const FXchar *msg):FXErrorException(msg){} 78 }; 79 80 81 /** 82 * Invalid pointer. 83 */ 84 class FXAPI FXPointerException : public FXErrorException { 85 private: 86 static const FXchar exceptionName[]; 87 public: FXPointerException()88 FXPointerException():FXErrorException(FXPointerException::exceptionName){} FXPointerException(const FXchar * msg)89 FXPointerException(const FXchar *msg):FXErrorException(msg){} 90 }; 91 92 93 /** 94 * Generic resource exception. 95 */ 96 class FXAPI FXResourceException : public FXException { 97 private: 98 static const FXchar exceptionName[]; 99 public: FXResourceException()100 FXResourceException():FXException(FXResourceException::exceptionName){} FXResourceException(const FXchar * msg)101 FXResourceException(const FXchar *msg):FXException(msg){} 102 }; 103 104 105 /** 106 * Out of memory. 107 */ 108 class FXAPI FXMemoryException : public FXResourceException { 109 private: 110 static const FXchar exceptionName[]; 111 public: FXMemoryException()112 FXMemoryException():FXResourceException(FXMemoryException::exceptionName){} FXMemoryException(const FXchar * msg)113 FXMemoryException(const FXchar *msg):FXResourceException(msg){} 114 }; 115 116 117 /** 118 * Window exception. 119 */ 120 class FXAPI FXWindowException : public FXResourceException { 121 private: 122 static const FXchar exceptionName[]; 123 public: FXWindowException()124 FXWindowException():FXResourceException(FXWindowException::exceptionName){} FXWindowException(const FXchar * msg)125 FXWindowException(const FXchar *msg):FXResourceException(msg){} 126 }; 127 128 129 /** 130 * Image, cursor, bitmap exception. 131 */ 132 class FXAPI FXImageException : public FXResourceException { 133 private: 134 static const FXchar exceptionName[]; 135 public: FXImageException()136 FXImageException():FXResourceException(FXImageException::exceptionName){} FXImageException(const FXchar * msg)137 FXImageException(const FXchar *msg):FXResourceException(msg){} 138 }; 139 140 141 /** 142 * Font exception. 143 */ 144 class FXAPI FXFontException : public FXResourceException { 145 private: 146 static const FXchar exceptionName[]; 147 public: FXFontException()148 FXFontException():FXResourceException(FXFontException::exceptionName){} FXFontException(const FXchar * msg)149 FXFontException(const FXchar *msg):FXResourceException(msg){} 150 }; 151 152 153 /** 154 * Throw this exception to terminate the calling thread gracefully, and 155 * pass the given return code back to a possible join() operation if one 156 * is in effect. 157 */ 158 class FXAPI FXThreadException : public FXException { 159 private: 160 FXint exitcode; 161 private: 162 static const FXchar exceptionName[]; 163 public: FXException(FXThreadException::exceptionName)164 FXThreadException(FXint xc=-1):FXException(FXThreadException::exceptionName),exitcode(xc){} FXException(msg)165 FXThreadException(const FXchar *msg,FXint xc=-1):FXException(msg),exitcode(xc){} code()166 FXint code() const { return exitcode; } 167 }; 168 169 } 170 171 #endif 172