1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef _LOG4CXX_HELPERS_EXCEPTION_H 19 #define _LOG4CXX_HELPERS_EXCEPTION_H 20 21 #include <exception> 22 #include <log4cxx/log4cxx.h> 23 #include <log4cxx/logstring.h> 24 25 #ifdef _MSC_VER 26 #pragma warning ( push ) 27 #pragma warning (disable : 4251 4275) // ::std::exception needs to have dll-interface 28 #endif 29 30 namespace log4cxx 31 { 32 namespace helpers 33 { 34 /** The class Exception and its subclasses indicate conditions that a 35 reasonable application might want to catch. 36 */ 37 class LOG4CXX_EXPORT Exception : public ::std::exception 38 { 39 public: 40 Exception(const char* msg); 41 Exception(const LogString& msg); 42 Exception(const Exception& src); 43 Exception& operator=(const Exception& src); 44 const char* what() const throw(); 45 private: 46 enum { MSG_SIZE = 128 }; 47 char msg[MSG_SIZE + 1]; 48 }; // class Exception 49 50 /** RuntimeException is the parent class of those exceptions that can be 51 thrown during the normal operation of the process. 52 */ 53 class LOG4CXX_EXPORT RuntimeException : public Exception 54 { 55 public: 56 RuntimeException(log4cxx_status_t stat); 57 RuntimeException(const LogString& msg); 58 RuntimeException(const RuntimeException& msg); 59 RuntimeException& operator=(const RuntimeException& src); 60 private: 61 static LogString formatMessage(log4cxx_status_t stat); 62 }; // class RuntimeException 63 64 /** Thrown when an application attempts to use null in a case where an 65 object is required. 66 */ 67 class LOG4CXX_EXPORT NullPointerException : public RuntimeException 68 { 69 public: 70 NullPointerException(const LogString& msg); 71 NullPointerException(const NullPointerException& msg); 72 NullPointerException& operator=(const NullPointerException& src); 73 }; // class NullPointerException 74 75 /** Thrown to indicate that a method has been passed 76 an illegal or inappropriate argument.*/ 77 class LOG4CXX_EXPORT IllegalArgumentException : public RuntimeException 78 { 79 public: 80 IllegalArgumentException(const LogString& msg); 81 IllegalArgumentException(const IllegalArgumentException&); 82 IllegalArgumentException& operator=(const IllegalArgumentException&); 83 }; // class IllegalArgumentException 84 85 /** Signals that an I/O exception of some sort has occurred. This class 86 is the general class of exceptions produced by failed or interrupted 87 I/O operations. 88 */ 89 class LOG4CXX_EXPORT IOException : public Exception 90 { 91 public: 92 IOException(); 93 IOException(log4cxx_status_t stat); 94 IOException(const LogString& msg); 95 IOException(const IOException& src); 96 IOException& operator=(const IOException&); 97 private: 98 static LogString formatMessage(log4cxx_status_t stat); 99 }; 100 101 class LOG4CXX_EXPORT MissingResourceException : public Exception 102 { 103 public: 104 MissingResourceException(const LogString& key); 105 MissingResourceException(const MissingResourceException& src); 106 MissingResourceException& operator=(const MissingResourceException&); 107 private: 108 static LogString formatMessage(const LogString& key); 109 }; 110 111 class LOG4CXX_EXPORT PoolException : public Exception 112 { 113 public: 114 PoolException(log4cxx_status_t stat); 115 PoolException(const PoolException& src); 116 PoolException& operator=(const PoolException&); 117 private: 118 static LogString formatMessage(log4cxx_status_t stat); 119 }; 120 121 122 class LOG4CXX_EXPORT MutexException : public Exception 123 { 124 public: 125 MutexException(log4cxx_status_t stat); 126 MutexException(const MutexException& src); 127 MutexException& operator=(const MutexException&); 128 private: 129 static LogString formatMessage(log4cxx_status_t stat); 130 }; 131 132 class LOG4CXX_EXPORT InterruptedException : public Exception 133 { 134 public: 135 InterruptedException(); 136 InterruptedException(log4cxx_status_t stat); 137 InterruptedException(const InterruptedException& src); 138 InterruptedException& operator=(const InterruptedException&); 139 private: 140 static LogString formatMessage(log4cxx_status_t stat); 141 }; 142 143 class LOG4CXX_EXPORT ThreadException 144 : public Exception 145 { 146 public: 147 ThreadException(log4cxx_status_t stat); 148 ThreadException(const LogString& msg); 149 ThreadException(const ThreadException& src); 150 ThreadException& operator=(const ThreadException&); 151 private: 152 static LogString formatMessage(log4cxx_status_t stat); 153 }; 154 155 class LOG4CXX_EXPORT TranscoderException : public Exception 156 { 157 public: 158 TranscoderException(log4cxx_status_t stat); 159 TranscoderException(const TranscoderException& src); 160 TranscoderException& operator=(const TranscoderException&); 161 private: 162 static LogString formatMessage(log4cxx_status_t stat); 163 }; 164 165 class LOG4CXX_EXPORT IllegalMonitorStateException 166 : public Exception 167 { 168 public: 169 IllegalMonitorStateException(const LogString& msg); 170 IllegalMonitorStateException(const IllegalMonitorStateException& msg); 171 IllegalMonitorStateException& operator=(const IllegalMonitorStateException& msg); 172 }; 173 174 /** 175 Thrown when an application tries to create an instance of a class using 176 the newInstance method in class Class, but the specified class object 177 cannot be instantiated because it is an interface or is an abstract class. 178 */ 179 class LOG4CXX_EXPORT InstantiationException : public Exception 180 { 181 public: 182 InstantiationException(const LogString& msg); 183 InstantiationException(const InstantiationException& msg); 184 InstantiationException& operator=(const InstantiationException& msg); 185 }; 186 187 /** 188 Thrown when an application tries to load in a class through its 189 string name but no definition for the class with the specified name 190 could be found. 191 */ 192 class LOG4CXX_EXPORT ClassNotFoundException : public Exception 193 { 194 public: 195 ClassNotFoundException(const LogString& className); 196 ClassNotFoundException(const ClassNotFoundException& msg); 197 ClassNotFoundException& operator=(const ClassNotFoundException& msg); 198 private: 199 static LogString formatMessage(const LogString& className); 200 }; 201 202 203 class NoSuchElementException : public Exception 204 { 205 public: 206 NoSuchElementException(); 207 NoSuchElementException(const NoSuchElementException&); 208 NoSuchElementException& operator=(const NoSuchElementException&); 209 }; 210 211 class IllegalStateException : public Exception 212 { 213 public: 214 IllegalStateException(); 215 IllegalStateException(const IllegalStateException&); 216 IllegalStateException& operator=(const IllegalStateException&); 217 }; 218 219 /** Thrown to indicate that there is an error in the underlying 220 protocol, such as a TCP error. 221 */ 222 class LOG4CXX_EXPORT SocketException : public IOException 223 { 224 public: 225 SocketException(const LogString& msg); 226 SocketException(log4cxx_status_t status); 227 SocketException(const SocketException&); 228 SocketException& operator=(const SocketException&); 229 }; 230 231 /** Signals that an error occurred while attempting to connect a socket 232 to a remote address and port. Typically, the connection was refused 233 remotely (e.g., no process is listening on the remote address/port). 234 */ 235 class LOG4CXX_EXPORT ConnectException : public SocketException 236 { 237 public: 238 ConnectException(log4cxx_status_t status); 239 ConnectException(const ConnectException& src); 240 ConnectException& operator=(const ConnectException&); 241 }; 242 243 class LOG4CXX_EXPORT ClosedChannelException : public SocketException 244 { 245 public: 246 ClosedChannelException(); 247 ClosedChannelException(const ClosedChannelException& src); 248 ClosedChannelException& operator=(const ClosedChannelException&); 249 }; 250 251 /** Signals that an error occurred while attempting to bind a socket to 252 a local address and port. Typically, the port is in use, or the 253 requested local address could not be assigned. 254 */ 255 class LOG4CXX_EXPORT BindException : public SocketException 256 { 257 public: 258 BindException(log4cxx_status_t status); 259 BindException(const BindException&); 260 BindException& operator=(const BindException&); 261 }; 262 263 /** Signals that an I/O operation has been interrupted. An 264 InterruptedIOException is thrown to indicate that an input or output 265 transfer has been terminated because the thread performing it was 266 interrupted. The field bytesTransferred indicates how many bytes were 267 successfully transferred before the interruption occurred. 268 */ 269 class LOG4CXX_EXPORT InterruptedIOException : public IOException 270 { 271 public: 272 InterruptedIOException(const LogString& msg); 273 InterruptedIOException(const InterruptedIOException&); 274 InterruptedIOException& operator=(const InterruptedIOException&); 275 }; 276 277 278 /** Signals that an I/O operation has been interrupted. An 279 InterruptedIOException is thrown to indicate that an input or output 280 transfer has been terminated because the thread performing it was 281 interrupted. The field bytesTransferred indicates how many bytes were 282 successfully transferred before the interruption occurred. 283 */ 284 class LOG4CXX_EXPORT SocketTimeoutException : public InterruptedIOException 285 { 286 public: 287 SocketTimeoutException(); 288 SocketTimeoutException(const SocketTimeoutException&); 289 SocketTimeoutException& operator=(const SocketTimeoutException&); 290 }; 291 292 293 } // namespace helpers 294 } // namespace log4cxx 295 296 #if defined(_MSC_VER) 297 #pragma warning (pop) 298 #endif 299 300 #endif // _LOG4CXX_HELPERS_EXCEPTION_H 301