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#pragma once
21
22#include <boost/serialization/access.hpp>
23#include <boost/serialization/string.hpp>
24
25#include <string>
26#include <utility>
27
28namespace ErrorHandling {
29
30/** \brief A runtime error.
31 * This class describes a runtime error,
32 * including where it occurred and its
33 * severity.
34 */
36 enum class ErrorLevel { WARNING, ERROR };
37 RuntimeError() = default;
39 std::string function, std::string file, int line)
40 : m_level(level), m_who(who), m_what(std::move(what)),
41 m_function(std::move(function)), m_file(std::move(file)), m_line(line) {
42 }
43
44 /** The error level */
45 ErrorLevel level() const { return m_level; }
46 /** Which MPI node raised the error. */
47 int who() const { return m_who; }
48 /** The Error Message */
49 std::string what() const { return m_what; }
50 /** The function where the error occurred. */
51 std::string function() const { return m_function; }
52 /** The file where the error occurred. */
53 std::string file() const { return m_file; }
54 /** The line where the error occurred. */
55 int line() const { return m_line; }
56 /** Get a string representation */
57 std::string format() const;
58 void print() const;
59
60private:
61 /** Boost serialization */
63 template <class Archive> void serialize(Archive &ar, const unsigned int) {
64 ar & m_level;
65 ar & m_who;
66 ar & m_what;
67 ar & m_function;
68 ar & m_file;
69 ar & m_line;
70 }
71
72 ErrorLevel m_level;
73 int m_who;
74 std::string m_what;
75 std::string m_function;
76 std::string m_file;
77 int m_line;
78};
79
80} // namespace ErrorHandling
STL namespace.
ErrorLevel level() const
The error level.
int line() const
The line where the error occurred.
std::string what() const
The Error Message.
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)