Salome HOME
Module MULTIPR
[modules/multipr.git] / src / MULTIPR / MULTIPR_Exceptions.hxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_Exceptions.hxx
6  *
7  * \brief   All the exceptions used by MULTIPR.
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 #ifndef MULTIPR_EXCEPTIONS_HXX
15 #define MULTIPR_EXCEPTIONS_HXX
16
17 //*****************************************************************************
18 // Includes section
19 //*****************************************************************************
20
21 #include <string>
22 #include <iostream>
23
24
25 namespace multipr
26 {
27
28 //*****************************************************************************
29 // Class RuntimeException
30 // Super class for all exceptions used by the module MULTIPR
31 //*****************************************************************************
32
33 class RuntimeException
34 {
35 public:
36         
37         /**
38          * Constructor. Build a new RuntimeException.
39          * \param  pMsg   message to be associated with this exception.
40          * \param  pFile  name of the file where the probem occur (you can use the macro __FILE__); "unknown" by default.
41          * \param  pLine  number of the line where the probem occur (you can use the macro __LINE__); 0 by default.
42          */
43         RuntimeException(
44                 const std::string& pMsg, 
45                 const std::string& pFile = "unknown", 
46                 int                pLine = 0) 
47         { 
48                 mMsg  = pMsg; 
49                 mFile = pFile;
50                 mLine = pLine;
51                 mType = "RuntimeException";
52         }
53         
54         /**
55          * Dumps info about this exception to the given output stream.
56          */
57         void dump(std::ostream& pOs) const 
58         { 
59                 pOs << "MULTIPR: " << mType << " (" << mFile << ", line " << mLine << "): " << mMsg << std::endl; 
60         }
61         
62 protected:
63
64         std::string mMsg;    /**< Message associated with this exception. */
65         std::string mFile;   /**< Name of the source file where the problem occurs. */
66         int         mLine;   /**< Number of the line where the problem occurs. */
67         std::string mType;   /**< Type of this exception. */
68 };
69
70
71 //*****************************************************************************
72 // Class NullArgumentException
73 // Should be used for a NULL pointer
74 //*****************************************************************************
75
76 class NullArgumentException : public RuntimeException
77 {
78 public:
79         NullArgumentException(
80                 const std::string& pMsg, 
81                 const std::string& pFile="unknown", 
82                 int pLine=0) : RuntimeException(pMsg, pFile, pLine) 
83         { 
84                 mType = "NullArgumentException";
85         }
86 };
87
88
89 //*****************************************************************************
90 // Class IllegalArgumentException
91 // Should be used when a parameter is invalid (check precondition)
92 //*****************************************************************************
93
94 class IllegalArgumentException : public RuntimeException
95 {
96 public:
97         IllegalArgumentException(
98                 const std::string& pMsg, 
99                 const std::string& pFile="unknown", 
100                 int pLine=0) : RuntimeException(pMsg, pFile, pLine) 
101         { 
102                 mType = "IllegalArgumentException";
103         }
104 };
105
106
107 //*****************************************************************************
108 // Class IllegalStateException
109 // Should be used when the internal state of an object is invalid
110 //*****************************************************************************
111
112 class IllegalStateException : public RuntimeException
113 {
114 public:
115         IllegalStateException(
116                 const std::string& pMsg, 
117                 const std::string& pFile="unknown", 
118                 int pLine=0) : RuntimeException(pMsg, pFile, pLine)
119         { 
120                 mType = "IllegalStateException";
121         }
122 };
123
124
125 //*****************************************************************************
126 // Class IndexOutOfBoundsException
127 // Should be used when an index is out of bounds
128 //*****************************************************************************
129
130 class IndexOutOfBoundsException : public RuntimeException
131 {
132 public:
133         IndexOutOfBoundsException(
134                 const std::string& pMsg, 
135                 const std::string& pFile="unknown", 
136                 int pLine=0) : RuntimeException(pMsg, pFile, pLine)
137         { 
138                 mType = "IndexOutOfBoundsException";
139         }
140 };
141
142
143 //*****************************************************************************
144 // Class IOException
145 // Should be used when any i/o error occurs
146 //*****************************************************************************
147
148 class IOException : public RuntimeException
149 {
150 public:
151         IOException(
152                 const std::string& pMsg, 
153                 const std::string& pFile="unknown", 
154                 int pLine=0) : RuntimeException(pMsg, pFile, pLine)
155         { 
156                 mType = "IOException";
157         }
158 };
159
160
161 //*****************************************************************************
162 // Class FileNotFoundException
163 // Should be used to indicate that a file has not been found
164 //*****************************************************************************
165
166 class FileNotFoundException : public IOException
167 {
168 public:
169         FileNotFoundException(
170                 const std::string& pMsg, 
171                 const std::string& pFile="unknown", 
172                 int pLine=0) : IOException(pMsg, pFile, pLine)
173         { 
174                 mType = "FileNotFoundException";
175         }
176 };
177
178
179 //*****************************************************************************
180 // Class UnsupportedOperationException
181 // Should be used when a function/method is not yet implemented or 
182 // if an operation is not supported in a given context
183 //*****************************************************************************
184
185 class UnsupportedOperationException : public RuntimeException
186 {
187 public:
188         UnsupportedOperationException(
189                 const std::string& pMsg, 
190                 const std::string& pFile="unknown", 
191                 int pLine=0) : RuntimeException(pMsg, pFile, pLine)
192         { 
193                 mType = "UnsupportedOperationException";
194         }
195 };
196
197
198 } // namespace MULTIPR
199
200
201 #endif // MULTIPR_EXCEPTIONS_HXX
202
203 // EOF