The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
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>
16#include <exception>
17#include <memory>
18#include <ostream>
19#include <string>
20
29class GAUDI_API GaudiException : virtual public std::exception {
30 friend class StatusCode;
31
32public:
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
122protected:
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};
#define GAUDI_API
Definition Kernel.h:49
Define general base for Gaudi exception.
virtual const std::string & message() const
error message to be printed
static bool s_proc
"previous" element in the linked list
virtual const StatusCode & code() const
StatusCode for Exception.
GaudiException(std::string Message, std::string Tag, StatusCode Code)
Constructor (1)
std::string m_message
StatusCode m_code
exception tag
virtual const std::string & setTag(const std::string &newTag)
update name tag
friend class StatusCode
virtual GaudiException * clone() const
clone operation
virtual const std::string & setMessage(const std::string &newMessage)
update the error message to be printed
std::unique_ptr< GaudiException > m_previous
stack trace at instantiation
std::string m_tag
error message
const char * what() const override
method from std::exception
std::string m_backTrace
status code for exception
virtual const std::string & backTrace() const
return the stack trace at instantiation
virtual GaudiException * previous() const
get the previous exception ( "previous" element in the linked list)
virtual const std::string & tag() const
name tag for the exception, or exception type
virtual const StatusCode & setCode(const StatusCode &newStatus)
update the status code for the exception
The Message class.
Definition Message.h:25
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
STL namespace.
ostream & operator<<(ostream &s, const MyCustomType &m)