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-2015.
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: Stephan Aiche$
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 #ifdef OPENMS_COMPILER_MSVC
143  static void newHandler();
144 #else
145  static void newHandler() throw(OutOfMemory);
146 #endif
147 
156 
158  static std::string & file_()
159  {
160  static std::string * file_ = 0;
161  if (file_ == 0)
162  {
163  file_ = new std::string;
164  *file_ = "unknown";
165  }
166  return *file_;
167  }
168 
170  static int & line_()
171  {
172  static int * line_ = 0;
173  if (line_ == 0)
174  {
175  line_ = new int;
176  *line_ = -1;
177  }
178  return *line_;
179  }
180 
182  static std::string & function_()
183  {
184  static std::string * function_ = 0;
185  if (function_ == 0)
186  {
187  function_ = new std::string;
188  *function_ = "unknown";
189  }
190  return *function_;
191  }
192 
194  static std::string & name_()
195  {
196  static std::string * name_ = 0;
197  if (name_ == 0)
198  {
199  name_ = new std::string;
200  *name_ = "unknown exception";
201  }
202  return *name_;
203  }
204 
206  static std::string & what_()
207  {
208  static std::string * what_ = 0;
209  if (what_ == 0)
210  {
211  what_ = new std::string;
212  *what_ = " - ";
213  }
214  return *what_;
215  }
216 
218  };
219 
220  } // namespace Exception
221 
222 } // namespace OpenMS
223 
224 #endif // OPENMS_CONCEPT_GLOBALEXCEPTIONHANDLER_H
~GlobalExceptionHandler()
Definition: GlobalExceptionHandler.h:85
STL namespace.
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:206
OpenMS global exception handler.
Definition: GlobalExceptionHandler.h:54
Out of memory exception.
Definition: Exception.h:472
static std::string & name_()
wrapper for static member name_
Definition: GlobalExceptionHandler.h:194
static std::string & file_()
wrapper for static member file_
Definition: GlobalExceptionHandler.h:158
GlobalExceptionHandler(const GlobalExceptionHandler &)
private version of c'tor to avoid initialization
Definition: GlobalExceptionHandler.h:83
static std::string & function_()
wrapper for static member function_
Definition: GlobalExceptionHandler.h:182
static int & line_()
wrapper for static member line_
Definition: GlobalExceptionHandler.h:170

OpenMS / TOPP release 2.0.0 Documentation generated on Thu Aug 20 2015 01:44:23 using doxygen 1.8.9.1