/[escript]/branches/windows_from_1456_trunk_1522_merged_in/esysUtils/src/EsysException.h
ViewVC logotype

Annotation of /branches/windows_from_1456_trunk_1522_merged_in/esysUtils/src/EsysException.h

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26