]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/src/Error.hpp
This commit was generated by cvs2svn to compensate for changes in r11742,
[u/mrichter/AliRoot.git] / HLT / MUON / src / Error.hpp
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Author: Artur Szostak
4 // Email:  artur@alice.phy.uct.ac.za | artursz@iafrica.com
5 //
6 ////////////////////////////////////////////////////////////////////////////////
7
8 #ifndef dHLT_ERROR_HPP
9 #define dHLT_ERROR_HPP
10
11 #include "BasicTypes.hpp"
12 #include <exception>
13 #include <ostream>
14
15 namespace dHLT
16 {
17
18
19 class Error : public std::exception
20 {
21 public:
22
23         Error() throw() {};
24         virtual ~Error() throw() {};
25
26         /* Should return a human readable string containing a description of the
27            error.
28          */
29         virtual const char* Message() const throw() = 0;
30         
31         /* Returns an error code describing the error. The error code should be
32            unique to the entire system
33          */
34         virtual Int ErrorCode() const throw() = 0;
35         
36         virtual const char* what() const throw()
37         {
38                 return Message();
39         };
40         
41         /* Define the << operator for streams to be able to do something like:
42
43                Error myerror;
44                cout << myerror << endl;
45         */
46         friend std::ostream& operator << (std::ostream& os, const dHLT::Error& error)
47         {
48                 os << error.Message();
49                 return os;
50         };
51 };
52
53
54 class OutOfMemory : public Error
55 {
56 public:
57         virtual const char* Message() const throw();
58         virtual Int ErrorCode() const throw();
59 };
60
61
62 /* When one needs to indicate that no more memory is available one should use the
63    ThrowOutOfMemory method rather than explicitly using the code
64        throw OutOfMemory();
65    This is because the ThrowOutOfMemory routine throws a preallocated object so
66    we are safe from having to allocate more (nonexistant) memory.
67  */
68 void ThrowOutOfMemory() throw (OutOfMemory);
69
70
71 // Error code declarations.
72 enum
73 {
74         OUT_OF_MEMORY = 0x10000001
75 };
76
77
78 }; // dHLT
79
80 #endif // dHLT_ERROR_HPP