DATRW++ library: seismic data I/O with multiple formats
exception.h
Go to the documentation of this file.
1 /*! \file exception.h
2  * \brief libdatrwxx exception class (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 07/07/2016
8  *
9  * libdatrwxx exception class (prototypes)
10  *
11  * \ingroup group_error
12  *
13  * Copyright (c) 2016 by Thomas Forbriger (BFO Schiltach)
14  *
15  * ----
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29  * ----
30  *
31  * REVISIONS and CHANGES
32  * - 07/07/2016 V1.0 Thomas Forbriger
33  *
34  * ============================================================================
35  */
36 
37 // include guard
38 #ifndef DATRW_EXCEPTION_H_VERSION
39 
40 #define DATRW_EXCEPTION_H_VERSION \
41  "DATRW_EXCEPTION_H V1.0"
42 
43 #include <string>
44 
45 namespace datrw {
46 
47  /*! \brief Base class for exceptions
48  *
49  * This is an exception base class. It holds some information about the
50  * reason for throwing the exception. The information is printed to cerr
51  * through function report(). This function may be overloaded by a derived
52  * type. But its functionality is still accessible through base_report().
53  *
54  * The standard behaviour is to print out the message during object
55  * initialization. If you don't like this, call dont_report_on_construct().
56  *
57  * \ingroup group_error
58  * \sa DATRW_Xassert
59  * \sa DATRW_assert
60  * \sa DATRW_abort
61  */
62  class Exception
63  {
64  public:
65  //! Creates exception with no explaning comments
66  Exception();
67  //! Creates an exception with an explanation message
68  Exception(const std::string& message);
69  //! Creates an exception with message and failed assertion
70  Exception(const std::string& message,
71  const std::string& condition);
72  //! Create with message, failed assertion, and code position
73  Exception(const std::string& message,
74  const std::string& file,
75  const int& line,
76  const std::string& condition);
77  //! Create with message and code position
78  Exception(const std::string& message,
79  const std::string& file,
80  const int& line);
81  //! provide explicit virtual destructor
82  virtual ~Exception() { }
83  //! Screen report
84  virtual void report() const;
85  //! Issue a screen report on construction of exception
86  static void report_on_construct();
87  //! Issue NO screen report on construction of exception
88  static void dont_report_on_construct();
89  //! set report on construct flag
90  static void report_on_construct_flag(const bool& flag)
91  { Mreport_on_construct=flag; }
92  //! return report on construct flag
94  protected:
95  //! Screen report
96  void base_report() const;
97  private:
98  //! Shall we print to cerr at construction time?
99  static bool Mreport_on_construct;
100  //! pointer to message string
101  std::string Mmessage;
102  //! pointer to file name string
103  std::string Mfile;
104  //! pointer to line number in source file
105  const int& Mline;
106  //! pointer to assertion condition text string
107  std::string Mcondition;
108  }; // class Exception
109 
110 } // namespace datrw
111 
112 #endif // DATRW_EXCEPTION_H_VERSION (includeguard)
113 
114 /* ----- END OF exception.h ----- */
static void report_on_construct_flag(const bool &flag)
set report on construct flag
Definition: exception.h:90
static bool report_on_construct_flag()
return report on construct flag
Definition: exception.h:93
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: exception.cc:90
static bool Mreport_on_construct
Shall we print to cerr at construction time?
Definition: exception.h:99
virtual ~Exception()
provide explicit virtual destructor
Definition: exception.h:82
const int & Mline
pointer to line number in source file
Definition: exception.h:105
Exception()
Creates exception with no explaning comments.
Definition: exception.cc:53
Base class for exceptions.
Definition: exception.h:62
std::string Mmessage
pointer to message string
Definition: exception.h:101
Root namespace of library.
Definition: aalibdatrwxx.cc:16
static void report_on_construct()
Issue a screen report on construction of exception.
Definition: exception.cc:84
std::string Mfile
pointer to file name string
Definition: exception.h:103
void base_report() const
Screen report.
Definition: exception.cc:102
std::string Mcondition
pointer to assertion condition text string
Definition: exception.h:107
virtual void report() const
Screen report.
Definition: exception.cc:96