thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Utilities
Exception.h
1
// -*- C++ -*-
2
//
3
// Exception.h is a part of ThePEG - Toolkit for HEP Event Generation
4
// Copyright (C) 1999-2019 Leif Lonnblad
5
//
6
// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8
//
9
#ifndef ThePEG_Exception_H
10
#define ThePEG_Exception_H
11
// This is the declaration of the Exception class.
12
13
#include <exception>
14
#include "
ThePEG/Config/ThePEG.h
"
15
#include "Exception.fh"
16
#include <string>
17
#include <iosfwd>
18
19
extern
"C"
{
20
void
breakThePEG();
21
}
22
23
namespace
ThePEG
{
24
44
class
Exception
:
public
exception {
45
46
public
:
47
51
enum
Severity
{
52
unknown
,
53
info
,
55
warning
,
57
setuperror
,
59
eventerror
,
61
runerror
,
63
maybeabort
,
65
abortnow
68
};
69
70
public
:
71
77
Exception
(
const
string
& str,
Severity
sev);
78
82
Exception
() :
handled
(false),
theSeverity
(
unknown
) { breakThePEG(); }
83
87
Exception
(
const
Exception
& ex)
88
:
std
::exception(ex),
theMessage
(ex.
message
()),
89
handled
(ex.
handled
),
theSeverity
(ex.
severity
())
90
{
91
ex.
handle
();
92
}
93
97
virtual
~Exception
() noexcept;
98
99
public:
100
104
const
Exception
& operator=(const
Exception
& ex) {
105
handled
= ex.handled;
106
theMessage
<< ex.message();
107
theSeverity
= ex.severity();
108
ex.handle();
109
return
*
this
;
110
}
111
115
bool
operator==
(
const
Exception
& ex)
const
{
116
return
(
message
() == ex.
message
() &&
severity
() == ex.
severity
() );
117
}
118
123
bool
operator<
(
const
Exception
& ex)
const
{
124
return
(
severity
() == ex.
severity
() ?
125
(
message
() < ex.
message
() ) :
126
(
severity
() < ex.
severity
() ) );
127
}
128
129
public
:
130
134
virtual
const
char
*
what
() const noexcept {
135
static
string
str;
136
str =
message
();
137
return
str.c_str();
138
}
139
143
string
message
()
const
{
144
string
mess =
theMessage
.str();
145
return
mess.empty() ? string(
"Error message not provided."
) : mess;
146
}
147
151
void
writeMessage
(ostream & os = *
errstream
)
const
;
152
156
Severity
severity
()
const
{
return
theSeverity
; }
157
161
void
handle
()
const
{
handled
=
true
; }
162
166
template
<
typename
T>
167
Exception
&
operator<<
(
const
T & t) {
168
theMessage
<< t;
169
return
*
this
;
170
}
171
175
Exception
&
operator<<
(
Severity
sev) {
176
severity
(sev);
177
return
*
this
;
178
}
179
180
protected
:
181
185
void
severity
(
Severity
);
186
190
mutable
ostringstream
theMessage
;
191
192
private
:
193
197
mutable
bool
handled
;
198
202
Severity
theSeverity
;
203
207
static
ostream *
errstream
;
208
209
public
:
210
215
static
bool
noabort
;
216
217
};
218
219
}
220
221
#endif
/* ThePEG_Exception_H */
ThePEG.h
This is the main config header file for ThePEG.
ThePEG::Exception
Exception is the base class for all exceptions to be used in ThePEG.
Definition:
Exception.h:44
ThePEG::Exception::operator==
bool operator==(const Exception &ex) const
Comparison.
Definition:
Exception.h:115
ThePEG::Exception::operator<<
Exception & operator<<(const T &t)
Add info to the exception message.
Definition:
Exception.h:167
ThePEG::Exception::writeMessage
void writeMessage(ostream &os= *errstream) const
Write the error message to a stream.
ThePEG::Exception::theSeverity
Severity theSeverity
The severity.
Definition:
Exception.h:202
ThePEG::Exception::theMessage
ostringstream theMessage
Stream to write the error message to.
Definition:
Exception.h:190
ThePEG::Exception::operator<<
Exception & operator<<(Severity sev)
Set the severity for the exception.
Definition:
Exception.h:175
ThePEG::Exception::severity
void severity(Severity)
set the severity.
ThePEG::Exception::severity
Severity severity() const
Return the severity.
Definition:
Exception.h:156
ThePEG::Exception::errstream
static ostream * errstream
The default stream to write the error message if unhandled.
Definition:
Exception.h:207
ThePEG::Exception::what
virtual const char * what() const noexcept
Return the error message.
Definition:
Exception.h:134
ThePEG::Exception::message
string message() const
Return the error message.
Definition:
Exception.h:143
ThePEG::Exception::Exception
Exception()
Default constructor.
Definition:
Exception.h:82
ThePEG::Exception::handle
void handle() const
Indicate that this exception has been taken care of.
Definition:
Exception.h:161
ThePEG::Exception::Severity
Severity
The levels of severity.
Definition:
Exception.h:51
ThePEG::Exception::warning
@ warning
Possibly severe, (the user should be warned).
Definition:
Exception.h:55
ThePEG::Exception::eventerror
@ eventerror
Possibly severe, (the event being generated should be discarded).
Definition:
Exception.h:59
ThePEG::Exception::maybeabort
@ maybeabort
Severe error, (the run should be terminated, possibly dumping core).
Definition:
Exception.h:63
ThePEG::Exception::info
@ info
Not severe (but the user should be informed).
Definition:
Exception.h:53
ThePEG::Exception::unknown
@ unknown
Unknown severity.
Definition:
Exception.h:52
ThePEG::Exception::abortnow
@ abortnow
Severe error, (the run is aborted immediately, before the exception is thrown).
Definition:
Exception.h:65
ThePEG::Exception::runerror
@ runerror
Severe error, (the run should be terminated).
Definition:
Exception.h:61
ThePEG::Exception::setuperror
@ setuperror
Command failed during setup phase, execution is continued.
Definition:
Exception.h:57
ThePEG::Exception::Exception
Exception(const Exception &ex)
The copy constructor.
Definition:
Exception.h:87
ThePEG::Exception::operator<
bool operator<(const Exception &ex) const
Compare severity.
Definition:
Exception.h:123
ThePEG::Exception::noabort
static bool noabort
If this flag is set, all abortnow and maybeabort severities will be treated as runerror.
Definition:
Exception.h:215
ThePEG::Exception::Exception
Exception(const string &str, Severity sev)
Standard constructor.
ThePEG::Exception::~Exception
virtual ~Exception() noexcept
The destructor.
ThePEG::Exception::handled
bool handled
True if this exception has been taken care of.
Definition:
Exception.h:197
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
std
STL namespace.
Generated on Thu Jun 20 2024 14:47:02 for ThePEG by
1.9.6