OpenMS
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-2023.
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 #pragma once
36 
37 #include <OpenMS/CONCEPT/Types.h>
39 
40 #include <string>
41 
42 namespace OpenMS
43 {
44 
45  namespace Exception
46  {
47 
53  class OPENMS_DLLAPI GlobalExceptionHandler
54  {
55 private:
59 
77  throw();
78 
80 
83 
85 public:
86 
89  {
90  static GlobalExceptionHandler * globalExceptionHandler_;
91 
92  if (globalExceptionHandler_ == nullptr)
93  {
94  globalExceptionHandler_ = new GlobalExceptionHandler;
95  }
96  return *globalExceptionHandler_;
97  }
98 
102 
105  static void setName(const std::string & name)
106  throw();
107 
110  static void setMessage(const std::string & message)
111  throw();
112 
115  static void setLine(int line)
116  throw();
117 
120  static void setFile(const std::string & file)
121  throw();
122 
125  static void setFunction(const std::string & function)
126  throw();
127 
130  static void set(const std::string & file, int line, const std::string & function,
131  const std::string & name, const std::string & message)
132  throw();
134 protected:
135 
137  static void terminate()
138  throw();
139 
141  static void newHandler();
142 
151 
153  static std::string & file_()
154  {
155  static std::string * file_ = nullptr;
156  if (file_ == nullptr)
157  {
158  file_ = new std::string;
159  *file_ = "unknown";
160  }
161  return *file_;
162  }
163 
165  static int & line_()
166  {
167  static int * line_ = nullptr;
168  if (line_ == nullptr)
169  {
170  line_ = new int;
171  *line_ = -1;
172  }
173  return *line_;
174  }
175 
177  static std::string & function_()
178  {
179  static std::string * function_ = nullptr;
180  if (function_ == nullptr)
181  {
182  function_ = new std::string;
183  *function_ = "unknown";
184  }
185  return *function_;
186  }
187 
189  static std::string & name_()
190  {
191  static std::string * name_ = nullptr;
192  if (name_ == nullptr)
193  {
194  name_ = new std::string;
195  *name_ = "unknown exception";
196  }
197  return *name_;
198  }
199 
201  static std::string & what_()
202  {
203  static std::string * what_ = nullptr;
204  if (what_ == nullptr)
205  {
206  what_ = new std::string;
207  *what_ = " - ";
208  }
209  return *what_;
210  }
211 
213  };
214 
215  } // namespace Exception
216 
217 } // namespace OpenMS
218 
OpenMS global exception handler.
Definition: GlobalExceptionHandler.h:54
static GlobalExceptionHandler & getInstance()
The accessor for the singleton. It also serves as a replacement for the constructor.
Definition: GlobalExceptionHandler.h:88
static void setFunction(const std::string &function)
static void setName(const std::string &name)
static void terminate()
The OPENMS replacement for terminate.
GlobalExceptionHandler()
Default constructor.
static void setFile(const std::string &file)
~GlobalExceptionHandler()
Definition: GlobalExceptionHandler.h:84
static int & line_()
wrapper for static member line_
Definition: GlobalExceptionHandler.h:165
static void set(const std::string &file, int line, const std::string &function, const std::string &name, const std::string &message)
static std::string & what_()
wrapper for static member what_
Definition: GlobalExceptionHandler.h:201
static std::string & function_()
wrapper for static member function_
Definition: GlobalExceptionHandler.h:177
static void setMessage(const std::string &message)
static std::string & name_()
wrapper for static member name_
Definition: GlobalExceptionHandler.h:189
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48