ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
RuntimeError.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef ESPRESSO_SRC_CORE_ERROR_HANDLING_RUNTIME_ERROR_HPP
21#define ESPRESSO_SRC_CORE_ERROR_HANDLING_RUNTIME_ERROR_HPP
22
23#include <boost/serialization/access.hpp>
24#include <boost/serialization/string.hpp>
25
26#include <string>
27#include <utility>
28
29namespace ErrorHandling {
30
31/** \brief A runtime error.
32 * This class describes a runtime error,
33 * including where it occurred and its
34 * severity.
35 */
37 /** The error level, warnings are only displayed to the user,
38 * errors are fatal.
39 */
40 enum class ErrorLevel { DEBUG, INFO, WARNING, ERROR };
41 RuntimeError() = default;
43 std::string function, std::string file, int line)
44 : m_level(level), m_who(who), m_what(std::move(what)),
45 m_function(std::move(function)), m_file(std::move(file)), m_line(line) {
46 }
47
48 /** The error level */
49 ErrorLevel level() const { return m_level; }
50 /** Which MPI node raised the error. */
51 int who() const { return m_who; }
52 /** The Error Message */
53 std::string what() const { return m_what; }
54 /** The function where the error occurred. */
55 std::string function() const { return m_function; }
56 /** The file where the error occurred. */
57 std::string file() const { return m_file; }
58 /** The line where the error occurred. */
59 int line() const { return m_line; }
60 /** Get a string representation */
61 std::string format() const;
62 void print() const;
63
64private:
65 /** Boost serialization */
67 template <class Archive> void serialize(Archive &ar, const unsigned int) {
68 ar & m_level;
69 ar & m_who;
70 ar & m_what;
71 ar & m_function;
72 ar & m_file;
73 ar & m_line;
74 }
75
76 ErrorLevel m_level;
77 int m_who;
78 std::string m_what;
79 std::string m_function;
80 std::string m_file;
81 int m_line;
82};
83
84} // namespace ErrorHandling
85
86#endif
ErrorLevel level() const
The error level.
int line() const
The line where the error occurred.
std::string what() const
The Error Message.
ErrorLevel
The error level, warnings are only displayed to the user, errors are fatal.
std::string format() const
Get a string representation.
friend class boost::serialization::access
Boost serialization.
std::string function() const
The function where the error occurred.
int who() const
Which MPI node raised the error.
std::string file() const
The file where the error occurred.
RuntimeError(ErrorLevel level, int who, std::string what, std::string function, std::string file, int line)