FastJet 3.0.2
Error.hh
00001 #ifndef __FASTJET_ERROR_HH__
00002 #define __FASTJET_ERROR_HH__
00003 
00004 //STARTHEADER
00005 // $Id: Error.hh 2577 2011-09-13 15:11:38Z salam $
00006 //
00007 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
00008 //
00009 //----------------------------------------------------------------------
00010 // This file is part of FastJet.
00011 //
00012 //  FastJet is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU General Public License as published by
00014 //  the Free Software Foundation; either version 2 of the License, or
00015 //  (at your option) any later version.
00016 //
00017 //  The algorithms that underlie FastJet have required considerable
00018 //  development and are described in hep-ph/0512210. If you use
00019 //  FastJet as part of work towards a scientific publication, please
00020 //  include a citation to the FastJet paper.
00021 //
00022 //  FastJet is distributed in the hope that it will be useful,
00023 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 //  GNU General Public License for more details.
00026 //
00027 //  You should have received a copy of the GNU General Public License
00028 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
00029 //----------------------------------------------------------------------
00030 //ENDHEADER
00031 
00032 #include<iostream>
00033 #include<string>
00034 #include "fastjet/internal/base.hh"
00035 
00036 FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
00037 
00038 /// @ingroup error_handling
00039 /// \class Error
00040 /// base class corresponding to errors that can be thrown by FastJet
00041 class Error {
00042 public:
00043   /// default constructors
00044   Error() {}
00045 
00046   /// ctor from an error message
00047   ///   \param message to be printed
00048   /// Note: in addition to the error message, one can choose to print the
00049   /// backtrace (showing the last few calls before the error) by 
00050   /// using set_print_backtrace(true). The default is "false".
00051   Error(const std::string & message);
00052 
00053   /// virtual dummy dtor
00054   virtual ~Error() {}
00055 
00056   /// the error message
00057   std::string message() const {return _message;}
00058 
00059   /// controls whether the error message (and the backtrace, if its printing is enabled) 
00060   /// is printed out or not
00061   static void set_print_errors(bool print_errors) {_print_errors = print_errors;}
00062 
00063   /// controls whether the backtrace is printed out with the error message or not.
00064   /// The default is "false".
00065   static void set_print_backtrace(bool enabled) {_print_backtrace = enabled;}
00066 
00067   /// sets the default output stream for all errors; by default
00068   /// cerr; if it's null then error output is suppressed.
00069   static void set_default_stream(std::ostream * ostr) {
00070     _default_ostr = ostr;
00071   }
00072 
00073 private:
00074   std::string _message;                ///< error message
00075   static bool _print_errors;           ///< do we print anything?
00076   static bool _print_backtrace;        ///< do we print the backtrace?
00077   static std::ostream * _default_ostr; ///< the output stream (cerr if not set)
00078 };
00079 
00080 
00081 FASTJET_END_NAMESPACE
00082 
00083 #endif // __FASTJET_ERROR_HH__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends