FastJet  3.0.6
Error.hh
1 #ifndef __FASTJET_ERROR_HH__
2 #define __FASTJET_ERROR_HH__
3 
4 //STARTHEADER
5 // $Id: Error.hh 2577 2011-09-13 15:11:38Z salam $
6 //
7 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
8 //
9 //----------------------------------------------------------------------
10 // This file is part of FastJet.
11 //
12 // FastJet is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // The algorithms that underlie FastJet have required considerable
18 // development and are described in hep-ph/0512210. If you use
19 // FastJet as part of work towards a scientific publication, please
20 // include a citation to the FastJet paper.
21 //
22 // FastJet is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 // GNU General Public License for more details.
26 //
27 // You should have received a copy of the GNU General Public License
28 // along with FastJet. If not, see <http://www.gnu.org/licenses/>.
29 //----------------------------------------------------------------------
30 //ENDHEADER
31 
32 #include<iostream>
33 #include<string>
34 #include "fastjet/internal/base.hh"
35 
36 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
37 
38 /// @ingroup error_handling
39 /// \class Error
40 /// base class corresponding to errors that can be thrown by FastJet
41 class Error {
42 public:
43  /// default constructors
44  Error() {}
45 
46  /// ctor from an error message
47  /// \param message to be printed
48  /// Note: in addition to the error message, one can choose to print the
49  /// backtrace (showing the last few calls before the error) by
50  /// using set_print_backtrace(true). The default is "false".
51  Error(const std::string & message);
52 
53  /// virtual dummy dtor
54  virtual ~Error() {}
55 
56  /// the error message
57  std::string message() const {return _message;}
58 
59  /// controls whether the error message (and the backtrace, if its printing is enabled)
60  /// is printed out or not
61  static void set_print_errors(bool print_errors) {_print_errors = print_errors;}
62 
63  /// controls whether the backtrace is printed out with the error message or not.
64  /// The default is "false".
65  static void set_print_backtrace(bool enabled) {_print_backtrace = enabled;}
66 
67  /// sets the default output stream for all errors; by default
68  /// cerr; if it's null then error output is suppressed.
69  static void set_default_stream(std::ostream * ostr) {
70  _default_ostr = ostr;
71  }
72 
73 private:
74  std::string _message; ///< error message
75  static bool _print_errors; ///< do we print anything?
76  static bool _print_backtrace; ///< do we print the backtrace?
77  static std::ostream * _default_ostr; ///< the output stream (cerr if not set)
78 };
79 
80 
81 FASTJET_END_NAMESPACE
82 
83 #endif // __FASTJET_ERROR_HH__
fastjet::Error::message
std::string message() const
the error message
Definition: Error.hh:57
fastjet::Error::Error
Error()
default constructors
Definition: Error.hh:44
fastjet::Error::~Error
virtual ~Error()
virtual dummy dtor
Definition: Error.hh:54
fastjet::Error::set_print_errors
static void set_print_errors(bool print_errors)
controls whether the error message (and the backtrace, if its printing is enabled) is printed out or ...
Definition: Error.hh:61
fastjet::Error::set_default_stream
static void set_default_stream(std::ostream *ostr)
sets the default output stream for all errors; by default cerr; if it's null then error output is sup...
Definition: Error.hh:69
fastjet::Error::set_print_backtrace
static void set_print_backtrace(bool enabled)
controls whether the backtrace is printed out with the error message or not.
Definition: Error.hh:65
fastjet::Error
Definition: Error.hh:41