cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Exception.h
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2013-2022 Laurent Forthomme
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef CepGen_Core_Exception_h
20#define CepGen_Core_Exception_h
21
23
24namespace cepgen {
25 class Exception : public LoggedMessage, public std::runtime_error {
26 public:
28 enum Type {
29 undefined = -1,
31 fatal
32 };
33 explicit Exception(const char* mod,
34 const char* from = "",
36 const char* file = "",
37 short lineno = 0) noexcept;
39 virtual ~Exception() noexcept override;
40
42 friend std::ostream& operator<<(std::ostream&, const Type&);
43
44 template <typename T>
45 inline friend const Exception& operator<<(const Exception& exc, const T& var) noexcept {
46 (const LoggedMessage&)exc << var;
47 return exc;
48 }
50 void dump(std::ostream* os = nullptr) const noexcept override;
51
52 const char* what() const noexcept override;
53
54 private:
55 Type type_{Type::undefined};
56 mutable char what_[50]{""};
57 };
58} // namespace cepgen
59
60#define CG_ERROR(mod) cepgen::Exception(mod, __FUNC__, cepgen::Exception::Type::error, __FILE__, __LINE__)
61#define CG_FATAL(mod) cepgen::Exception(mod, __FUNC__, cepgen::Exception::Type::fatal, __FILE__, __LINE__)
62#define CG_ASSERT(assertion) \
63 if (!(assertion)) \
64 throw CG_FATAL("Assertion") << "Assertion '" << #assertion << " failed.";
65
66#endif
Type
Enumeration of exception severities.
Definition Exception.h:28
@ fatal
Critical and stopping error.
Definition Exception.h:31
@ error
General non-stopping error.
Definition Exception.h:30
@ undefined
Irregular message.
Definition Exception.h:29
const char * what() const noexcept override
Definition Exception.cpp:36
void dump(std::ostream *os=nullptr) const noexcept override
Human-readable dump of the exception.
Definition Exception.cpp:41
A simple exception handler.
Definition Message.h:44
const std::string & from() const
Origin of the exception.
Definition Message.h:161
const MessageType & type() const
Message type.
Definition Message.h:167
const std::string & file() const
File where the exception occured.
Definition Message.h:163
Common namespace for this Monte Carlo generator.