Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:38

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_GAUDIEXCEPTION_H
0012 #define GAUDIKERNEL_GAUDIEXCEPTION_H
0013 
0014 // Include files
0015 #include "GaudiKernel/Kernel.h"
0016 #include "GaudiKernel/MsgStream.h"
0017 #include "GaudiKernel/StatusCode.h"
0018 
0019 #include <exception>
0020 #include <iostream>
0021 #include <string>
0022 
0023 /**
0024  * @class GaudiException GaudiException.h GaudiKernel/GaudiException.h
0025  *
0026  * Define general base for Gaudi exception
0027  *
0028  * @author Vanya Belyaev
0029  * @author Sebastien Ponce
0030  */
0031 class GAUDI_API GaudiException : virtual public std::exception {
0032   friend class StatusCode;
0033 
0034 public:
0035   /** Constructor (1)
0036       @param Message error message
0037       @param Tag "name tag", or exeption type
0038       @param Code status code
0039   */
0040   GaudiException( std::string Message, std::string Tag, StatusCode Code );
0041 
0042   /** Constructor (2)
0043       @param Message error message
0044       @param Tag "name tag", or exeption type
0045       @param Code status code
0046       @param Exception "previous"  exception
0047   */
0048   GaudiException( std::string Message, std::string Tag, StatusCode Code, const GaudiException& Exception );
0049 
0050   /** Constructor (3)
0051       @param Message error message
0052       @param Tag "name tag", or exeption type
0053       @param Code status code
0054       @param Exception "previous" exception (used to improve the error message)
0055   */
0056   GaudiException( std::string Message, std::string Tag, StatusCode Code, const std::exception& Exception );
0057 
0058   /// Copy constructor (deep copying!)
0059   GaudiException( const GaudiException& Exception );
0060 
0061   /// destructor (perform the deletion of "previous" field!)
0062   virtual ~GaudiException() throw();
0063 
0064   /// assignment operator
0065   GaudiException& operator=( const GaudiException& Exception );
0066 
0067   ///  error message to be printed
0068   virtual const std::string& message() const { return m_message; }
0069 
0070   /// update the error message to be printed
0071   virtual const std::string& setMessage( const std::string& newMessage ) {
0072     m_message = newMessage;
0073     return message();
0074   }
0075 
0076   ///  name tag for the exception, or exception type
0077   virtual const std::string& tag() const { return m_tag; }
0078 
0079   /// update name tag
0080   virtual const std::string& setTag( const std::string& newTag ) {
0081     m_tag = newTag;
0082     return tag();
0083   }
0084 
0085   /// StatusCode for Exception
0086   virtual const StatusCode& code() const { return m_code; }
0087 
0088   ///  update the status code for the exception
0089   virtual const StatusCode& setCode( const StatusCode& newStatus ) {
0090     m_code = newStatus;
0091     return code();
0092   }
0093 
0094   /// get the previous exception ( "previous" element in the linked list)
0095   virtual GaudiException* previous() const { return m_previous.get(); }
0096 
0097   /// return the stack trace at instantiation
0098   virtual const std::string& backTrace() const { return m_backTrace; }
0099 
0100   /// methods  for overloaded printout to std::ostream& and MsgStream&
0101   virtual std::ostream& printOut( std::ostream& os = std::cerr ) const;
0102 
0103   /// Output the exception to the Gaudi MsgStream
0104   virtual MsgStream& printOut( MsgStream& os ) const;
0105 
0106   /// clone operation
0107   virtual GaudiException* clone() const { return new GaudiException( *this ); }
0108 
0109   /// method from std::exception
0110   const char* what() const throw() override { return message().c_str(); }
0111 
0112 protected:
0113   std::string                     m_message;   /// error message
0114   std::string                     m_tag;       /// exception tag
0115   StatusCode                      m_code;      /// status code for exception
0116   std::string                     m_backTrace; /// stack trace at instantiation
0117   std::unique_ptr<GaudiException> m_previous;  /// "previous" element in the linked list
0118   static bool                     s_proc;
0119 };
0120 
0121 /// overloaded printout to std::ostream
0122 std::ostream& operator<<( std::ostream& os, const GaudiException& ge );
0123 
0124 /// overloaded printout to std::ostream
0125 std::ostream& operator<<( std::ostream& os, const GaudiException* pge );
0126 
0127 /// overloaded printout to MsgStream
0128 MsgStream& operator<<( MsgStream& os, const GaudiException& ge );
0129 
0130 /// overloaded printout to MsgStream
0131 MsgStream& operator<<( MsgStream& os, const GaudiException* pge );
0132 
0133 #endif // GAUDIKERNEL_GAUDIEXCEPTION_H