μHAL (v2.7.9)
Part of the IPbus software repository
exception.hpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Andrew Rose, Imperial College, London
25  email: awr01 <AT> imperial.ac.uk
26 
27  Marc Magrans de Abril, CERN
28  email: marc.magrans.de.abril <AT> cern.ch
29 
30 ---------------------------------------------------------------------------
31 */
32 
39 #ifndef _uhal_log_exception_hpp_
40 #define _uhal_log_exception_hpp_
41 
42 
43 #include <exception>
44 #include <string>
45 #include <sys/time.h>
46 
47 
49 #define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS( ClassName , BaseClassName, ClassDescription )\
50  class ClassName : public BaseClassName {\
51  public:\
52  ClassName() : BaseClassName() {}\
53  ClassName(const std::string& aMessage) : BaseClassName() {append(aMessage.c_str());}\
54  void throwAsDerivedType(){ throw ClassName(*this); } \
55  protected:\
56  std::string description() const throw() { return std::string( ClassDescription ); } \
57 };
58 
59 #define UHAL_DEFINE_EXCEPTION_CLASS( ClassName , ClassDescription ) UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, uhal::exception::exception, ClassDescription)
60 
61 
62 namespace uhal
63 {
64 
66  namespace exception
67  {
68 
70  class exception : public std::exception
71  {
72  public:
73 
74  exception ();
75 
76  exception ( const exception& aExc );
77 
84 
85  virtual ~exception() throw();
86 
92  virtual const char* what() const throw();
93 
95  virtual void throwAsDerivedType() = 0;
96 
101  void append ( const char* aCStr ) throw();
102 
103 
104  protected:
109  virtual std::string description() const throw() = 0;
110 
111  private:
113  timeval mTime;
114 
116  char* mString;
117  };
118 
119  }
120 }
121 
122 
123 #endif
uhal::exception::exception::what
virtual const char * what() const
Function which returns the error message associated with an exception If no error message has previou...
Definition: exception.cpp:87
uhal::exception::exception::mTime
timeval mTime
The time at which the exception was thrown.
Definition: exception.hpp:113
uhal::exception::exception::append
void append(const char *aCStr)
Add additional information to the exception message.
Definition: exception.cpp:104
uhal::exception::exception
An abstract base exception class, including an interface to throw as the derived type (for passing ex...
Definition: exception.hpp:71
uhal::exception::exception::description
virtual std::string description() const =0
Return the description associated with this type of exception.
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::exception::exception::~exception
virtual ~exception()
Definition: exception.cpp:77
uhal::exception::exception::throwAsDerivedType
virtual void throwAsDerivedType()=0
Function which casts a pointer from the base type of this object to a derived type of this object and...
uhal::exception::exception::operator=
exception & operator=(const exception &aExc)
Assignment operator.
Definition: exception.cpp:70
uhal::exception::exception::aExc
exception const exception & aExc
Definition: exception.hpp:76
uhal::exception::exception::mString
char * mString
Memory into which message is added by calls to append.
Definition: exception.hpp:116