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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1448 - (hide annotations)
Thu Feb 28 12:31:04 2008 UTC (15 years, 1 month ago) by phornby
File MIME type: text/plain
File size: 4336 byte(s)
Derived a consistent method of derivation from EsysException embodied in
EsysExceptionTestCase.cpp.
Eliminated xxxxException::operator=(). It was not used, and just made more work.

run_tests passes on linux.


1 ksteube 1312
2     /* $Id$ */
3    
4     /*******************************************************
5 trankine 1441 *
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 1447 #include <iostream>
23 jgs 82
24 trankine 1439 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 trankine 1439 \version 1.0.0
31 jgs 82
32 trankine 1439 \section class_desc Class Description:
33     A base class for exception classes used within Esys system.
34 jgs 82
35 trankine 1439 \section class_limits Class Limitations:
36     None
37 jgs 82
38 trankine 1439 \section class_conds Class Conditions of Use:
39     None
40 jgs 82
41 trankine 1439 \section throws Throws:
42     None
43 jgs 82
44 trankine 1439 */
45 phornby 1448 class EsysException : public std::exception
46     {
47 trankine 1439
48 phornby 1448 typedef std::exception Parent;
49    
50 jgs 82 public:
51 trankine 1439 /**
52     \brief
53     Default Constructor. Creates an exception with no message.
54     */
55     EsysException();
56    
57     /**
58     * \brief
59     Constructor which creates a EsysException with the given message
60 jgs 82
61 trankine 1439 @param exceptionReason Input - Exception message.
62     */
63     EsysException(const std::string &exceptionReason);
64 jgs 121
65 trankine 1439 /**
66     * \brief
67     Constructor which creates a EsysException with the given message
68 jgs 121
69 trankine 1439 @param cStr - Exception message.
70     */
71     EsysException( const char *cStr );
72 jgs 121
73 trankine 1439 /**
74     * \brief
75     Copy constructor
76 jgs 121
77 phornby 1448 @param other Input - EsysException
78 trankine 1439 */
79 phornby 1448 EsysException(const EsysException &other);
80 jgs 121
81 trankine 1439 /// Destructor
82 phornby 1447 virtual ~EsysException() THROW();
83 trankine 1439
84     /**
85     \brief
86     Return the exception message in the form
87     &lt;Exception Name&gt;: &lt;Exception Message&gt;
88    
89     @return the exception message.
90     */
91     const std::string & toString() const;
92    
93     /**
94     \brief
95     Return the name of the exception. This is expected to be overloaded
96     in derived classes with the derived class name.
97    
98     @return the name of the exception.
99     */
100     virtual const std::string & exceptionName() const;
101    
102     /**
103     \brief
104     Return a reference to the string that contains the exception reason.
105 jgs 121
106 trankine 1439 @return the string for the exception reason.
107     */
108     const std::string& reason() const;
109    
110     /**
111     \brief
112     set the string for the reason for the exception.
113     This allows ousiders to modify m_reason, but the practice is discouraged.
114     If string insertions are required, use string methods.
115     */
116     void setReason(const std::string &new_reason);
117    
118     /**
119     \brief
120     Return a description of the exception in the same format as the toString
121     method.
122    
123     @return a description of the exception.
124     */
125 phornby 1447 virtual const char* what() const THROW();
126 trankine 1439
127    
128     /**
129     \brief
130     update m_exceptionMessage after a reason update.
131     **/
132 trankine 1441 void updateMessage();
133 trankine 1439
134 trankine 1445
135 trankine 1444 private:
136 trankine 1439 //
137     // the exception reason
138     std::string m_reason;
139    
140     //
141     // the full exception message
142     std::string m_exceptionMessage;
143    
144     //
145     // the exception name is immutable and class-wide.
146     // Inheritor note; you need one of these too.
147 trankine 1441 // and an overloaded exceptionName() in your .cpp implementation file.
148 trankine 1439 static const std::string exceptionNameValue;
149    
150     };
151    
152 jgs 82 /**
153 trankine 1439 \brief
154     Stream insertion (print) operator for EsysExceptions
155 jgs 121
156 trankine 1439 @param output Input - Output stream.
157     @param inException Input - The exception to be inserted into the output
158     stream.
159     */
160     std::ostream &operator<<(std::ostream &output, EsysException &inException);
161 jgs 121
162 jgs 82
163 trankine 1439 ////////////////////////////////////////////////////////////////////
164    
165 trankine 1441 inline
166 trankine 1439 const std::string & EsysException::reason() const
167     {
168     return m_reason;
169     }
170    
171     // return the message as a std::string
172 trankine 1441 inline
173 trankine 1439 const std::string & EsysException::toString() const
174     {
175     return m_exceptionMessage;
176     }
177    
178 trankine 1441 inline
179 trankine 1439 void EsysException::setReason(const std::string &new_reason)
180     {
181     m_reason = new_reason;
182     updateMessage();
183     }
184    
185 trankine 1441 inline
186 phornby 1447 const char* EsysException::what() const THROW()
187 trankine 1439 {
188     return m_exceptionMessage.c_str();
189     }
190    
191    
192    
193 trankine 1441 inline
194 trankine 1439 void EsysException::updateMessage()
195     {
196     m_exceptionMessage = exceptionName() + ": " + m_reason;
197     }
198    
199 jgs 82 }
200    
201     #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26