Escript  Revision_4320
EsysException.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 
17 #ifndef ESYSEXCEPTION_H
18 #define ESYSEXCEPTION_H
19 #include "system_dep.h"
20 
21 #include <string>
22 #include <exception>
23 #include <iostream>
24 
25 namespace esysUtils
26 {
30  class EsysException : public std::exception
31  {
32 
33  protected:
34 
35  typedef std::exception Parent;
36 
37 
38  public:
44  EsysException();
45 
53  EsysException(const std::string &exceptionReason);
54 
62  EsysException( const char *cStr );
63 
71  EsysException(const EsysException &other);
72 
75  virtual ~EsysException() THROW(NO_ARG);
76 
88  operator=(const EsysException &other) THROW(NO_ARG);
89 
97  inline
98  const std::string & toString() const;
99 
108  virtual const std::string & exceptionName() const;
109 
116  inline
117  const std::string& reason() const;
118 
125  inline
126  void setReason(const std::string &new_reason);
127 
136  inline
137  virtual const char* what() const THROW(NO_ARG);
138 
139 
144  inline
145  void updateMessage();
146 
147 
148  private:
149  //
150  // the exception reason
151  std::string m_reason;
152 
153  //
154  // the full exception message
155  std::string m_exceptionMessage;
156 
157  //
158  // the exception name is immutable and class-wide.
159  // Inheritor note; you need one of these too.
160  // and an overloaded exceptionName() in your .cpp implementation file.
161  static const std::string exceptionNameValue;
162 
163  };
164 
174  std::ostream &operator<<(std::ostream &output, EsysException &inException);
175 
176 
178 
179  const std::string & EsysException::reason() const
180  {
181  return m_reason;
182  }
183 
184  // return the message as a std::string
185  const std::string & EsysException::toString() const
186  {
187  return m_exceptionMessage;
188  }
189 
190  void EsysException::setReason(const std::string &new_reason)
191  {
192  m_reason = new_reason;
193  updateMessage();
194  }
195 
196  const char* EsysException::what() const THROW(NO_ARG)
197  {
198  return m_exceptionMessage.c_str();
199  }
200 
202  {
204  }
205 
206 }
207 
208 #endif