OpenMS  2.6.0
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-2020.
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::Exception::GlobalExceptionHandler::line_
static int & line_()
wrapper for static member line_
Definition: GlobalExceptionHandler.h:165
LogStream.h
ToolDescription.h
OpenMS::Exception::GlobalExceptionHandler
OpenMS global exception handler.
Definition: GlobalExceptionHandler.h:53
OpenMS::Exception::GlobalExceptionHandler::GlobalExceptionHandler
GlobalExceptionHandler(const GlobalExceptionHandler &)
private version of c'tor to avoid initialization
Definition: GlobalExceptionHandler.h:82
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:144
OpenMS::Param::copy
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
OpenMS::Exception::GlobalExceptionHandler::~GlobalExceptionHandler
~GlobalExceptionHandler()
Definition: GlobalExceptionHandler.h:84
OpenMS::Param::ParamEntry
Parameter entry used to store the actual information inside of a Param entry.
Definition: Param.h:78
OpenMS::Internal::ToolExternalDetails
Definition: ToolDescription.h:106
OpenMS::Internal::MappingParam::pre_moves
std::vector< FileMapping > pre_moves
Definition: ToolDescription.h:69
OpenMS::DataValue::STRING_VALUE
string value
Definition: DataValue.h:67
Types.h
OpenMS::Internal::FileMapping
Maps input/output files to filenames for the external program.
Definition: ToolDescription.h:53
OpenMS::Exception::InvalidValue
Invalid value exception.
Definition: Exception.h:335
OpenMS::String::substitute
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
OpenMS::Internal::ToolDescriptionInternal::types
StringList types
-types of the tool (if any, e.g. ['centroided','wavelet'])
Definition: ToolDescription.h:88
OpenMS::Param::setValue
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
OpenMS::DataValue::toQString
QString toQString() const
Conversion to QString.
OpenMS::DataValue::STRING_LIST
string list
Definition: DataValue.h:70
OpenMS::Internal::ToolExternalDetails::text_fail
String text_fail
Definition: ToolDescription.h:109
OpenMS::Exception::GlobalExceptionHandler::name_
static std::string & name_()
wrapper for static member name_
Definition: GlobalExceptionHandler.h:189
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::String::trim
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
OpenMS::reverseComparator
ReverseComparator< Cmp > reverseComparator(Cmp const &cmp)
Make-function to create a ReverseComparator from another comparator without the need to specify the t...
Definition: ComparatorUtils.h:260
MzMLFile.h
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::Param::ParamEntry::tags
std::set< String > tags
Tags list, used e.g. for advanced parameter tag.
Definition: Param.h:108
OpenMS::Exception::GlobalExceptionHandler::getInstance
static GlobalExceptionHandler & getInstance()
The accessor for the singleton. It also serves as a replacement for the constructor.
Definition: GlobalExceptionHandler.h:88
OpenMS::ToolHandler::getExternalToolsPath
static String getExternalToolsPath()
get getOpenMSDataPath() + "/TOOLS/EXTERNAL"
OpenMS::Param::getValue
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
OpenMS::Exception::GlobalExceptionHandler::what_
static std::string & what_()
wrapper for static member what_
Definition: GlobalExceptionHandler.h:201
OpenMS::Internal::ToolExternalDetails::path
String path
filename to external tool
Definition: ToolDescription.h:113
OpenMS::File::remove
static bool remove(const String &file)
Removes a file (if it exists).
OPENMS_LOG_WARN
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:460
OpenMS::String::hasSubstring
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
OpenMS::Param::ParamEntry::value
DataValue value
Value associated with the entry.
Definition: Param.h:106
OpenMS::ListUtils::concatenate
static String concatenate(const std::vector< T > &container, const String &glue="")
Concatenates all elements of the container and puts the glue string between elements.
Definition: ListUtils.h:193
OpenMS::Internal::FileMapping::location
String location
a regex/macro mix; to be expanded by tool;
Definition: ToolDescription.h:55
OpenMS::Param::ParamIterator
Forward const iterator for the Param class.
Definition: Param.h:197
OpenMS::File::exists
static bool exists(const String &file)
Method used to test if a file exists.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::ToolHandler::getTOPPToolList
static ToolListType getTOPPToolList(const bool includeGenericWrapper=false)
Returns the list of official TOPP tools contained in the OpenMS/TOPP release.
UniqueIdGenerator.h
Exception.h
OpenMS::Param::exists
bool exists(const String &key) const
Tests if a parameter is set (expecting its fully qualified name, e.g., TextExporter:1:proteins_only)
OpenMS::Internal::ToolExternalDetails::text_finish
String text_finish
Definition: ToolDescription.h:110
int
OpenMS::Internal::ToolDescription::external_details
std::vector< ToolExternalDetails > external_details
additional details for external tools (one entry for each 'type')
Definition: ToolDescription.h:126
OpenMS::Exception::GlobalExceptionHandler::function_
static std::string & function_()
wrapper for static member function_
Definition: GlobalExceptionHandler.h:177
OpenMS::Internal::FileMapping::target
String target
TOPP parameter that determines the desired name.
Definition: ToolDescription.h:56
OpenMS::Internal::ToolExternalDetails::tr_table
MappingParam tr_table
Definition: ToolDescription.h:115
QProcess
Param.h
OpenMS::Param::size
Size size() const
Returns the number of entries (leafs).
OpenMS::String::toQString
QString toQString() const
Conversion to Qt QString.
OpenMS::UniqueIdGenerator::getUniqueId
static UInt64 getUniqueId()
Returns a new unique id.
OpenMS::DataValue::valueType
DataType valueType() const
returns the type of value stored
Definition: DataValue.h:365
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
OpenMS::SignedSize
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
OpenMS::ToolHandler::getTypes
static StringList getTypes(const String &toolname)
get all types of a tool (empty if none)
ComparatorUtils.h
OpenMS::Param::end
ParamIterator end() const
End iterator for the internal tree.
OPENMS_LOG_ERROR
#define OPENMS_LOG_ERROR
Macro to be used if non-fatal error are reported (processing continues)
Definition: LogStream.h:455
OpenMS::Param::begin
ParamIterator begin() const
Begin iterator for the internal tree.
OpenMS::Internal::MappingParam::mapping
std::map< Int, String > mapping
Definition: ToolDescription.h:68
OpenMS::Internal::ToolDescription
Definition: ToolDescription.h:122
String.h
OpenMS::Internal::ToolExternalDetails::commandline
String commandline
Definition: ToolDescription.h:112
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::File::getTempDirectory
static String getTempDirectory()
The current OpenMS temporary data path (for temporary files)
OpenMS::Param::getEntry
const ParamEntry & getEntry(const String &key) const
Returns the whole parameter entry.
OPENMS_LOG_INFO
#define OPENMS_LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:465
OpenMS::Internal::ToolExternalDetails::text_startup
String text_startup
Definition: ToolDescription.h:108
Factory.h
OpenMS::Internal::ToolExternalDetails::working_directory
String working_directory
folder where the command will be executed from
Definition: ToolDescription.h:114
File.h
TOPPBase.h
ToolHandler.h
OpenMS::Internal::MappingParam::post_moves
std::vector< FileMapping > post_moves
Definition: ToolDescription.h:70