Exception.h

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00037 //
00038 // Exception.h
00039 //
00040 // $Id: Exception.h,v 1.1 2008/03/31 19:13:30 iamcamiel Exp $
00041 //
00042 // Library: Foundation
00043 // Package: Core
00044 // Module:  Exception
00045 //
00046 // Definition of various Poco exception classes.
00047 //
00048 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
00049 // and Contributors.
00050 //
00051 // Permission is hereby granted, free of charge, to any person or organization
00052 // obtaining a copy of the software and accompanying documentation covered by
00053 // this license (the "Software") to use, reproduce, display, distribute,
00054 // execute, and transmit the Software, and to prepare derivative works of the
00055 // Software, and to permit third-parties to whom the Software is furnished to
00056 // do so, all subject to the following:
00057 // 
00058 // The copyright notices in the Software and this entire statement, including
00059 // the above license grant, this restriction and the following disclaimer,
00060 // must be included in all copies of the Software, in whole or in part, and
00061 // all derivative works of the Software, unless such copies or derivative
00062 // works are solely in the form of machine-executable object code generated by
00063 // a source language processor.
00064 // 
00065 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00066 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00067 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00068 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00069 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00070 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00071 // DEALINGS IN THE SOFTWARE.
00072 //
00073 
00074 
00075 #ifndef Foundation_Exception_INCLUDED
00076 #define Foundation_Exception_INCLUDED
00077 
00078 
00079 #include "VMS/Foundation.h"
00080 #include <stdexcept>
00081 
00082 
00083 namespace Poco {
00084 
00085 
00086 class Foundation_API Exception: public std::exception
00089 {
00090 public:
00091         Exception(const std::string& msg, int code = 0);
00093 
00094         Exception(const std::string& msg, const std::string& arg, int code = 0);
00096 
00097         Exception(const std::string& msg, const Exception& nested, int code = 0);
00100 
00101         Exception(const Exception& exc);
00103                 
00104         ~Exception() throw();
00106 
00107         Exception& operator = (const Exception& exc);
00109 
00110         virtual const char* name() const throw();
00112                 
00113         virtual const char* className() const throw();
00115                 
00116         virtual const char* what() const throw();
00120                 
00121         const Exception* nested() const;
00124                         
00125         const std::string& message() const;
00127                         
00128         int code() const;
00130                 
00131         std::string displayText() const;
00134 
00135         virtual Exception* clone() const;
00140                 
00141         virtual void rethrow() const;
00147 
00148 protected:
00149         Exception(int code = 0);
00151                 
00152 private:
00153         std::string _msg;
00154         Exception*  _pNested;
00155         int                     _code;
00156 };
00157 
00158 
00159 //
00160 // inlines
00161 //
00162 inline const Exception* Exception::nested() const
00163 {
00164         return _pNested;
00165 }
00166 
00167 
00168 inline const std::string& Exception::message() const
00169 {
00170         return _msg;
00171 }
00172 
00173 
00174 inline int Exception::code() const
00175 {
00176         return _code;
00177 }
00178 
00179 
00180 //
00181 // Macros for quickly declaring and implementing exception classes.
00182 // Unfortunately, we cannot use a template here because character
00183 // pointers (which we need for specifying the exception name)
00184 // are not allowed as template arguments.
00185 //
00186 #define POCO_DECLARE_EXCEPTION(API, CLS, BASE) \
00187         class API CLS: public BASE                                                                                                              \
00188         {                                                                                                                                                               \
00189         public:                                                                                                                                                 \
00190                 CLS(int code = 0);                                                                                                                      \
00191                 CLS(const std::string& msg, int code = 0);                                                                      \
00192                 CLS(const std::string& msg, const std::string& arg, int code = 0);                      \
00193                 CLS(const std::string& msg, const Poco::Exception& exc, int code = 0);          \
00194                 CLS(const CLS& exc);                                                                                                            \
00195                 ~CLS() throw();                                                                                                                         \
00196                 CLS& operator = (const CLS& exc);                                                                                       \
00197                 const char* name() const throw();                                                                                       \
00198                 const char* className() const throw();                                                                          \
00199                 Poco::Exception* clone() const;                                                                                         \
00200                 void rethrow() const;                                                                                                           \
00201         };
00202 
00203 
00204 #define POCO_IMPLEMENT_EXCEPTION(CLS, BASE, NAME)                                                                                                       \
00205         CLS::CLS(int code): BASE(code)                                                                                                                                  \
00206         {                                                                                                                                                                                               \
00207         }                                                                                                                                                                                               \
00208         CLS::CLS(const std::string& msg, int code): BASE(msg, code)                                                                             \
00209         {                                                                                                                                                                                               \
00210         }                                                                                                                                                                                               \
00211         CLS::CLS(const std::string& msg, const std::string& arg, int code): BASE(msg, arg, code)                \
00212         {                                                                                                                                                                                               \
00213         }                                                                                                                                                                                               \
00214         CLS::CLS(const std::string& msg, const Poco::Exception& exc, int code): BASE(msg, exc, code)    \
00215         {                                                                                                                                                                                               \
00216         }                                                                                                                                                                                               \
00217         CLS::CLS(const CLS& exc): BASE(exc)                                                                                                                             \
00218         {                                                                                                                                                                                               \
00219         }                                                                                                                                                                                               \
00220         CLS::~CLS() throw()                                                                                                                                                             \
00221         {                                                                                                                                                                                               \
00222         }                                                                                                                                                                                               \
00223         CLS& CLS::operator = (const CLS& exc)                                                                                                                   \
00224         {                                                                                                                                                                                               \
00225                 BASE::operator = (exc);                                                                                                                                         \
00226                 return *this;                                                                                                                                                           \
00227         }                                                                                                                                                                                               \
00228         const char* CLS::name() const throw()                                                                                                                   \
00229         {                                                                                                                                                                                               \
00230                 return NAME;                                                                                                                                                            \
00231         }                                                                                                                                                                                               \
00232         const char* CLS::className() const throw()                                                                                                              \
00233         {                                                                                                                                                                                               \
00234                 return typeid(*this).name();                                                                                                                            \
00235         }                                                                                                                                                                                               \
00236         Poco::Exception* CLS::clone() const                                                                                                                             \
00237         {                                                                                                                                                                                               \
00238                 return new CLS(*this);                                                                                                                                          \
00239         }                                                                                                                                                                                               \
00240         void CLS::rethrow() const                                                                                                                                               \
00241         {                                                                                                                                                                                               \
00242                 throw *this;                                                                                                                                                            \
00243         }
00244 
00245 
00246 //
00247 // Standard exception classes
00248 //
00249 POCO_DECLARE_EXCEPTION(Foundation_API, LogicException, Exception)
00250 POCO_DECLARE_EXCEPTION(Foundation_API, AssertionViolationException, LogicException)
00251 POCO_DECLARE_EXCEPTION(Foundation_API, NullPointerException, LogicException)
00252 POCO_DECLARE_EXCEPTION(Foundation_API, BugcheckException, LogicException)
00253 POCO_DECLARE_EXCEPTION(Foundation_API, InvalidArgumentException, LogicException)
00254 POCO_DECLARE_EXCEPTION(Foundation_API, NotImplementedException, LogicException)
00255 POCO_DECLARE_EXCEPTION(Foundation_API, RangeException, LogicException)
00256 POCO_DECLARE_EXCEPTION(Foundation_API, IllegalStateException, LogicException)
00257 POCO_DECLARE_EXCEPTION(Foundation_API, InvalidAccessException, LogicException)
00258 POCO_DECLARE_EXCEPTION(Foundation_API, SignalException, LogicException)
00259 POCO_DECLARE_EXCEPTION(Foundation_API, UnhandledException, LogicException)
00260 
00261 POCO_DECLARE_EXCEPTION(Foundation_API, RuntimeException, Exception)
00262 POCO_DECLARE_EXCEPTION(Foundation_API, NotFoundException, RuntimeException)
00263 POCO_DECLARE_EXCEPTION(Foundation_API, ExistsException, RuntimeException)
00264 POCO_DECLARE_EXCEPTION(Foundation_API, TimeoutException, RuntimeException)
00265 POCO_DECLARE_EXCEPTION(Foundation_API, SystemException, RuntimeException)
00266 POCO_DECLARE_EXCEPTION(Foundation_API, RegularExpressionException, RuntimeException)
00267 POCO_DECLARE_EXCEPTION(Foundation_API, LibraryLoadException, RuntimeException)
00268 POCO_DECLARE_EXCEPTION(Foundation_API, LibraryAlreadyLoadedException, RuntimeException)
00269 POCO_DECLARE_EXCEPTION(Foundation_API, NoThreadAvailableException, RuntimeException)
00270 POCO_DECLARE_EXCEPTION(Foundation_API, PropertyNotSupportedException, RuntimeException)
00271 POCO_DECLARE_EXCEPTION(Foundation_API, PoolOverflowException, RuntimeException)
00272 POCO_DECLARE_EXCEPTION(Foundation_API, NoPermissionException, RuntimeException)
00273 POCO_DECLARE_EXCEPTION(Foundation_API, OutOfMemoryException, RuntimeException)
00274 POCO_DECLARE_EXCEPTION(Foundation_API, DataException, RuntimeException)
00275 
00276 POCO_DECLARE_EXCEPTION(Foundation_API, DataFormatException, DataException)
00277 POCO_DECLARE_EXCEPTION(Foundation_API, SyntaxException, DataException)
00278 POCO_DECLARE_EXCEPTION(Foundation_API, CircularReferenceException, DataException)
00279 POCO_DECLARE_EXCEPTION(Foundation_API, PathSyntaxException, SyntaxException)
00280 POCO_DECLARE_EXCEPTION(Foundation_API, IOException, RuntimeException)
00281 POCO_DECLARE_EXCEPTION(Foundation_API, FileException, IOException)
00282 POCO_DECLARE_EXCEPTION(Foundation_API, FileExistsException, FileException)
00283 POCO_DECLARE_EXCEPTION(Foundation_API, FileNotFoundException, FileException)
00284 POCO_DECLARE_EXCEPTION(Foundation_API, PathNotFoundException, FileException)
00285 POCO_DECLARE_EXCEPTION(Foundation_API, FileReadOnlyException, FileException)
00286 POCO_DECLARE_EXCEPTION(Foundation_API, FileAccessDeniedException, FileException)
00287 POCO_DECLARE_EXCEPTION(Foundation_API, CreateFileException, FileException)
00288 POCO_DECLARE_EXCEPTION(Foundation_API, OpenFileException, FileException)
00289 POCO_DECLARE_EXCEPTION(Foundation_API, WriteFileException, FileException)
00290 POCO_DECLARE_EXCEPTION(Foundation_API, ReadFileException, FileException)
00291 POCO_DECLARE_EXCEPTION(Foundation_API, UnknownURISchemeException, RuntimeException)
00292 
00293 POCO_DECLARE_EXCEPTION(Foundation_API, ApplicationException, Exception)
00294 POCO_DECLARE_EXCEPTION(Foundation_API, BadCastException, RuntimeException)
00295 
00296 
00297 } // namespace Poco
00298 
00299 
00300 #endif // Foundation_Exception_INCLUDED

SourceForge.net Logo
Project space on SourceForge.net