Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
GlobalExceptionHandler.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg$
32 // $Authors: Stephan Aiche, Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_CONCEPT_GLOBALEXCEPTIONHANDLER_H
36 #define OPENMS_CONCEPT_GLOBALEXCEPTIONHANDLER_H
37 
38 #include <OpenMS/CONCEPT/Types.h>
40 
41 #include <string>
42 
43 namespace OpenMS
44 {
45 
46  namespace Exception
47  {
48 
54  class OPENMS_DLLAPI GlobalExceptionHandler
55  {
56 private:
60 
78  throw();
79 
81 
84 
86 public:
87 
90  {
91  static GlobalExceptionHandler * globalExceptionHandler_;
92 
93  if (globalExceptionHandler_ == 0)
94  {
95  globalExceptionHandler_ = new GlobalExceptionHandler;
96  }
97  return *globalExceptionHandler_;
98  }
99 
103 
106  static void setName(const std::string & name)
107  throw();
108 
111  static void setMessage(const std::string & message)
112  throw();
113 
116  static void setLine(int line)
117  throw();
118 
121  static void setFile(const std::string & file)
122  throw();
123 
126  static void setFunction(const std::string & function)
127  throw();
128 
131  static void set(const std::string & file, int line, const std::string & function,
132  const std::string & name, const std::string & message)
133  throw();
135 protected:
136 
138  static void terminate()
139  throw();
140 
142  static void newHandler();
143 
152 
154  static std::string & file_()
155  {
156  static std::string * file_ = 0;
157  if (file_ == 0)
158  {
159  file_ = new std::string;
160  *file_ = "unknown";
161  }
162  return *file_;
163  }
164 
166  static int & line_()
167  {
168  static int * line_ = 0;
169  if (line_ == 0)
170  {
171  line_ = new int;
172  *line_ = -1;
173  }
174  return *line_;
175  }
176 
178  static std::string & function_()
179  {
180  static std::string * function_ = 0;
181  if (function_ == 0)
182  {
183  function_ = new std::string;
184  *function_ = "unknown";
185  }
186  return *function_;
187  }
188 
190  static std::string & name_()
191  {
192  static std::string * name_ = 0;
193  if (name_ == 0)
194  {
195  name_ = new std::string;
196  *name_ = "unknown exception";
197  }
198  return *name_;
199  }
200 
202  static std::string & what_()
203  {
204  static std::string * what_ = 0;
205  if (what_ == 0)
206  {
207  what_ = new std::string;
208  *what_ = " - ";
209  }
210  return *what_;
211  }
212 
214  };
215 
216  } // namespace Exception
217 
218 } // namespace OpenMS
219 
220 #endif // OPENMS_CONCEPT_GLOBALEXCEPTIONHANDLER_H
~GlobalExceptionHandler()
Definition: GlobalExceptionHandler.h:85
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
static GlobalExceptionHandler & getInstance()
The accessor for the singleton. It also serves as a replacement for the constructor.
Definition: GlobalExceptionHandler.h:89
static std::string & what_()
wrapper for static member what_
Definition: GlobalExceptionHandler.h:202
OpenMS global exception handler.
Definition: GlobalExceptionHandler.h:54
static std::string & name_()
wrapper for static member name_
Definition: GlobalExceptionHandler.h:190
static std::string & file_()
wrapper for static member file_
Definition: GlobalExceptionHandler.h:154
GlobalExceptionHandler(const GlobalExceptionHandler &)
private version of c&#39;tor to avoid initialization
Definition: GlobalExceptionHandler.h:83
static std::string & function_()
wrapper for static member function_
Definition: GlobalExceptionHandler.h:178
static int & line_()
wrapper for static member line_
Definition: GlobalExceptionHandler.h:166

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:00 using doxygen 1.8.13