escript  Revision_
EsysException.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 #ifndef ESYSEXCEPTION_H
19 #define ESYSEXCEPTION_H
20 #include "system_dep.h"
21 
22 #include <string>
23 #include <exception>
24 #include <iostream>
25 
26 namespace esysUtils
27 {
31  class EsysException : public std::exception
32  {
33 
34  protected:
35 
36  typedef std::exception Parent;
37 
38 
39  public:
45  EsysException();
46 
54  EsysException(const std::string &exceptionReason);
55 
63  EsysException( const char *cStr );
64 
72  EsysException(const EsysException &other);
73 
76  virtual ~EsysException() THROW(NO_ARG);
77 
89  operator=(const EsysException &other) THROW(NO_ARG);
90 
98  inline
99  const std::string & toString() const;
100 
109  virtual const std::string & exceptionName() const;
110 
117  inline
118  const std::string& reason() const;
119 
126  inline
127  void setReason(const std::string &new_reason);
128 
137  inline
138  virtual const char* what() const THROW(NO_ARG);
139 
140 
145  inline
146  void updateMessage();
147 
148 
149  private:
150  //
151  // the exception reason
152  std::string m_reason;
153 
154  //
155  // the full exception message
157 
158  //
159  // the exception name is immutable and class-wide.
160  // Inheritor note; you need one of these too.
161  // and an overloaded exceptionName() in your .cpp implementation file.
162  static const std::string exceptionNameValue;
163 
164  };
165 
175  std::ostream &operator<<(std::ostream &output, EsysException &inException);
176 
177 
179 
180  const std::string & EsysException::reason() const
181  {
182  return m_reason;
183  }
184 
185  // return the message as a std::string
186  const std::string & EsysException::toString() const
187  {
188  return m_exceptionMessage;
189  }
190 
191  void EsysException::setReason(const std::string &new_reason)
192  {
193  m_reason = new_reason;
194  updateMessage();
195  }
196 
197  const char* EsysException::what() const THROW(NO_ARG)
198  {
199  return m_exceptionMessage.c_str();
200  }
201 
203  {
205  }
206 
207 }
208 
209 #endif
void updateMessage()
update m_exceptionMessage after a reason update.
Definition: EsysException.h:202
const std::string & reason() const
Return a reference to the string that contains the exception reason.
Definition: EsysException.h:180
A base class for exception classes used within Esys system.
Definition: EsysException.h:31
std::exception Parent
Definition: EsysException.h:36
#define NO_ARG
Definition: esysUtils/src/system_dep.h:56
static const std::string exceptionNameValue
Definition: EsysException.h:162
std::string m_reason
Definition: EsysException.h:152
STL namespace.
virtual ~EsysException()
Destructor.
Definition: EsysException.cpp:70
#define ESYSUTILS_DLL_API
Definition: esysUtils/src/system_dep.h:31
const std::string & toString() const
Return the exception message in the form <Exception Name>: <Exception Message>.
Definition: EsysException.h:186
virtual const char * what() const
Return a description of the exception in the same format as the toString method.
Definition: EsysException.h:197
#define THROW(ARG)
Definition: esysUtils/src/system_dep.h:53
Definition: Esys_MPI.cpp:32
EsysException()
Default Constructor. Creates an exception with no message.
Definition: EsysException.cpp:29
virtual const std::string & exceptionName() const
Return the name of the exception. This is expected to be overloaded in derived classes with the deriv...
Definition: EsysException.cpp:73
void setReason(const std::string &new_reason)
set the string for the reason for the exception. This allows ousiders to modify m_reason, but the practice is discouraged. If string insertions are required, use string methods.
Definition: EsysException.h:191
std::string m_exceptionMessage
Definition: EsysException.h:156