The Gaudi Framework  v40r0 (475e45c1)
GaudiException.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <GaudiKernel/Kernel.h>
14 #include <GaudiKernel/MsgStream.h>
15 #include <GaudiKernel/StatusCode.h>
16 #include <exception>
17 #include <memory>
18 #include <ostream>
19 #include <string>
20 
29 class GAUDI_API GaudiException : virtual public std::exception {
30  friend class StatusCode;
31 
32 public:
38  GaudiException( std::string Message, std::string Tag, StatusCode Code );
39 
46  GaudiException( std::string Message, std::string Tag, StatusCode Code, const GaudiException& Exception );
47 
54  GaudiException( std::string Message, std::string Tag, StatusCode Code, const std::exception& Exception );
55 
57  GaudiException( const GaudiException& Exception );
58 
60  virtual ~GaudiException() throw();
61 
63  GaudiException& operator=( const GaudiException& Exception );
64 
66  virtual const std::string& message() const { return m_message; }
67 
69  virtual const std::string& setMessage( const std::string& newMessage ) {
70  m_message = newMessage;
71  return message();
72  }
73 
75  virtual const std::string& tag() const { return m_tag; }
76 
78  virtual const std::string& setTag( const std::string& newTag ) {
79  m_tag = newTag;
80  return tag();
81  }
82 
84  virtual const StatusCode& code() const { return m_code; }
85 
87  virtual const StatusCode& setCode( const StatusCode& newStatus ) {
88  m_code = newStatus;
89  return code();
90  }
91 
93  virtual GaudiException* previous() const { return m_previous.get(); }
94 
96  virtual const std::string& backTrace() const { return m_backTrace; }
97 
99  virtual std::ostream& printOut( std::ostream& os = std::cerr ) const;
100 
102  virtual MsgStream& printOut( MsgStream& os ) const;
103 
105  virtual GaudiException* clone() const { return new GaudiException( *this ); }
106 
108  const char* what() const throw() override { return message().c_str(); }
109 
111  friend std::ostream& operator<<( std::ostream& os, const GaudiException& ge );
112 
114  friend std::ostream& operator<<( std::ostream& os, const GaudiException* pge );
115 
117  friend MsgStream& operator<<( MsgStream& os, const GaudiException& ge );
118 
120  friend MsgStream& operator<<( MsgStream& os, const GaudiException* pge );
121 
122 protected:
123  std::string m_message;
124  std::string m_tag;
126  std::string m_backTrace;
127  std::unique_ptr<GaudiException> m_previous;
128  static bool s_proc;
129 };
precedence.message
message
Definition: precedence.py:19
GaudiException::s_proc
static bool s_proc
"previous" element in the linked list
Definition: GaudiException.h:128
GaudiException::setMessage
virtual const std::string & setMessage(const std::string &newMessage)
update the error message to be printed
Definition: GaudiException.h:69
GaudiPartProp.decorators.std
std
Definition: decorators.py:32
GaudiException
Definition: GaudiException.h:29
GaudiException::m_previous
std::unique_ptr< GaudiException > m_previous
stack trace at instantiation
Definition: GaudiException.h:127
GaudiException::previous
virtual GaudiException * previous() const
get the previous exception ( "previous" element in the linked list)
Definition: GaudiException.h:93
StatusCode::m_code
code_t m_code
The status code value.
Definition: StatusCode.h:260
GaudiException::setCode
virtual const StatusCode & setCode(const StatusCode &newStatus)
update the status code for the exception
Definition: GaudiException.h:87
StatusCode.h
GaudiException::m_message
std::string m_message
Definition: GaudiException.h:123
GaudiException::backTrace
virtual const std::string & backTrace() const
return the stack trace at instantiation
Definition: GaudiException.h:96
StatusCode
Definition: StatusCode.h:64
Message
Definition: Message.h:25
Gaudi::Parsers::operator<<
std::ostream & operator<<(std::ostream &o, const Catalog &c)
printout operator
Definition: Catalog.h:49
GaudiException::setTag
virtual const std::string & setTag(const std::string &newTag)
update name tag
Definition: GaudiException.h:78
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:75
GaudiException::m_backTrace
std::string m_backTrace
status code for exception
Definition: GaudiException.h:126
GaudiException::m_tag
std::string m_tag
error message
Definition: GaudiException.h:124
MsgStream
Definition: MsgStream.h:29
GaudiException::clone
virtual GaudiException * clone() const
clone operation
Definition: GaudiException.h:105
GaudiException::code
virtual const StatusCode & code() const
StatusCode for Exception.
Definition: GaudiException.h:84
Kernel.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:83
GaudiException::what
const char * what() const override
method from std::exception
Definition: GaudiException.h:108
MsgStream.h
GaudiException::m_code
StatusCode m_code
exception tag
Definition: GaudiException.h:125