/[escript]/trunk/esysUtils/src/EsysException.h
ViewVC logotype

Annotation of /trunk/esysUtils/src/EsysException.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2019 - (hide annotations)
Mon Nov 10 13:49:00 2008 UTC (11 years, 10 months ago) by phornby
File MIME type: text/plain
File size: 4932 byte(s)
Yet another concerted effort to handle missing macro arguments
in a portable way.


1 ksteube 1312
2     /*******************************************************
3 phornby 1455 *
4 ksteube 1811 * Copyright (c) 2003-2008 by University of Queensland
5     * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7 phornby 1455 *
8 ksteube 1811 * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11 phornby 1455 *
12     *******************************************************/
13 ksteube 1312
14 ksteube 1811
15 jgs 82 #ifndef ESYSEXCEPTION_H
16     #define ESYSEXCEPTION_H
17 woo409 757 #include "system_dep.h"
18 jgs 82
19     #include <string>
20     #include <exception>
21 phornby 1455 #include <iostream>
22 jgs 82
23 phornby 1455 namespace esysUtils
24     {
25     /**
26     \page esys_exception Esys Exceptions
27     A base class for exception classes used within Esys system.
28 jgs 82
29 phornby 1455 \version 1.0.0
30 jgs 82
31 phornby 1455 \section class_desc Class Description:
32     A base class for exception classes used within Esys system.
33 jgs 82
34 phornby 1455 \section class_limits Class Limitations:
35     None
36 jgs 82
37 phornby 1455 \section class_conds Class Conditions of Use:
38     None
39 jgs 82
40 phornby 1455 \section throws Throws:
41     None
42 jgs 82
43 phornby 1455 */
44     class EsysException : public std::exception
45     {
46    
47     protected:
48    
49     typedef std::exception Parent;
50    
51    
52 jgs 82 public:
53 phornby 1455 /**
54     \brief
55     Default Constructor. Creates an exception with no message.
56     */
57 phornby 1628 ESYSUTILS_DLL_API
58 phornby 1455 EsysException();
59    
60     /**
61     * \brief
62     Constructor which creates a EsysException with the given message
63 jgs 82
64 phornby 1455 @param exceptionReason Input - Exception message.
65     */
66 phornby 1628 ESYSUTILS_DLL_API
67 phornby 1455 EsysException(const std::string &exceptionReason);
68 jgs 121
69 phornby 1455 /**
70     * \brief
71     Constructor which creates a EsysException with the given message
72 jgs 121
73 phornby 1455 @param cStr - Exception message.
74     */
75 phornby 1628 ESYSUTILS_DLL_API
76 phornby 1455 EsysException( const char *cStr );
77 jgs 121
78 phornby 1455 /**
79     * \brief
80     Copy constructor
81 jgs 121
82 phornby 1455 @param other Input - EsysException
83     */
84 phornby 1628 ESYSUTILS_DLL_API
85 phornby 1455 EsysException(const EsysException &other);
86 jgs 121
87 phornby 1455 /// Destructor
88 phornby 1628 ESYSUTILS_DLL_API
89 phornby 2017 virtual ~EsysException() THROW(NO_ARG);
90 phornby 1455
91     /**
92     \brief
93 phornby 1628 Assignment needed to override any automatic assignment
94     of std::exception, which can potentially copy around char *'s,
95     causeing trouble in some implementations of STL.
96     It will only copy the reason string, and update the message.
97    
98     @return re-assigned exception.
99     */
100     ESYSUTILS_DLL_API
101 phornby 1649 EsysException &
102 phornby 2019 operator=(const EsysException &other) THROW(NO_ARG);
103 phornby 1628
104     /**
105     \brief
106 phornby 1455 Return the exception message in the form
107     &lt;Exception Name&gt;: &lt;Exception Message&gt;
108    
109     @return the exception message.
110     */
111 phornby 1628 inline
112 phornby 1455 const std::string & toString() const;
113    
114     /**
115     \brief
116     Return the name of the exception. This is expected to be overloaded
117     in derived classes with the derived class name.
118    
119     @return the name of the exception.
120     */
121 phornby 1628 ESYSUTILS_DLL_API
122 phornby 1455 virtual const std::string & exceptionName() const;
123    
124     /**
125     \brief
126     Return a reference to the string that contains the exception reason.
127 jgs 121
128 phornby 1455 @return the string for the exception reason.
129     */
130 phornby 1628 inline
131 phornby 1455 const std::string& reason() const;
132    
133     /**
134     \brief
135     set the string for the reason for the exception.
136     This allows ousiders to modify m_reason, but the practice is discouraged.
137     If string insertions are required, use string methods.
138     */
139 phornby 1628 inline
140 phornby 1455 void setReason(const std::string &new_reason);
141    
142     /**
143     \brief
144     Return a description of the exception in the same format as the toString
145     method.
146    
147     @return a description of the exception.
148     */
149 phornby 1628 ESYSUTILS_DLL_API
150     inline
151 phornby 2019 virtual const char* what() const THROW(NO_ARG);
152 phornby 1455
153    
154     /**
155     \brief
156     update m_exceptionMessage after a reason update.
157     **/
158 phornby 1628 inline
159 phornby 1455 void updateMessage();
160    
161    
162     private:
163     //
164     // the exception reason
165     std::string m_reason;
166    
167     //
168     // the full exception message
169     std::string m_exceptionMessage;
170    
171     //
172     // the exception name is immutable and class-wide.
173     // Inheritor note; you need one of these too.
174     // and an overloaded exceptionName() in your .cpp implementation file.
175     static const std::string exceptionNameValue;
176    
177     };
178    
179 jgs 82 /**
180 phornby 1455 \brief
181     Stream insertion (print) operator for EsysExceptions
182 jgs 121
183 phornby 1455 @param output Input - Output stream.
184     @param inException Input - The exception to be inserted into the output
185     stream.
186     */
187 phornby 1628 ESYSUTILS_DLL_API
188 phornby 1455 std::ostream &operator<<(std::ostream &output, EsysException &inException);
189 jgs 121
190 jgs 82
191 phornby 1455 ////////////////////////////////////////////////////////////////////
192    
193     const std::string & EsysException::reason() const
194     {
195     return m_reason;
196     }
197    
198     // return the message as a std::string
199     const std::string & EsysException::toString() const
200     {
201     return m_exceptionMessage;
202     }
203    
204     void EsysException::setReason(const std::string &new_reason)
205     {
206     m_reason = new_reason;
207     updateMessage();
208     }
209    
210 phornby 2019 const char* EsysException::what() const THROW(NO_ARG)
211 phornby 1455 {
212     return m_exceptionMessage.c_str();
213     }
214    
215     void EsysException::updateMessage()
216     {
217     m_exceptionMessage = exceptionName() + ": " + m_reason;
218     }
219    
220 jgs 82 }
221    
222     #endif

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26