7 #include <yaml-cpp/yaml.h>
26 explicit Exception(
const std::string& what_arg,
const int exit_code_arg=1)
28 std::runtime_error(what_arg),
38 explicit Exception(
const char* what_arg,
const int exit_code_arg=1)
40 std::runtime_error(what_arg),
72 const std::string& prefix =
"")
83 std::stringstream msg;
85 if (prefix.length()) {
86 msg << prefix << std::endl;
89 msg <<
"KeyError: " << key << std::endl;
92 msg <<
"The given node is a Zombie! Make sure the node you are "
93 <<
"trying to read from is valid." << std::endl;
95 else if (node.size() == 0) {
96 msg <<
"The given node contains no entries! Make sure the desired "
97 <<
"key is available."
102 msg <<
"Make sure the desired key is available. The content of "
103 <<
"the given node is as follows:" << std::endl
104 << YAML::Dump(node) << std::endl;
116 template<
class VecT,
class Space>
118 const std::shared_ptr<Space>& space,
119 const std::string prefix = {})
122 std::stringstream emsg;
123 if (prefix.length() > 0) {
124 emsg << prefix <<
" ";
126 emsg <<
"The given position " << std::endl << invalid_pos
127 <<
"is not within the non-periodic space with extent"
128 << std::endl << space->extent;
139 template<
class exc_t>
141 std::cerr << exc.what() << std::endl;
142 return exc.exit_code;
The base exception class to derive Utopia-specific exceptions from.
Definition: exceptions.hh:15
const int exit_code
The exit code to use when exiting due to this exception.
Definition: exceptions.hh:18
Exception(const char *what_arg, const int exit_code_arg=1)
Construct an Utopia-specific exception.
Definition: exceptions.hh:38
Exception(const std::string &what_arg, const int exit_code_arg=1)
Construct an Utopia-specific exception.
Definition: exceptions.hh:26
An exception for when the program should end due to handling of a signal.
Definition: exceptions.hh:51
GotSignal(const int signum)
Construct a GotSignal exception, which has a standardized what message.
Definition: exceptions.hh:58
For access to a dict-like structure with a bad key.
Definition: exceptions.hh:67
KeyError(const std::string &key, const DataIO::Config &node, const std::string &prefix="")
Construct a KeyError exception, which has a standardized what message.
Definition: exceptions.hh:70
std::string generate_what_arg(std::string key, DataIO::Config node, std::string prefix)
Generates the what argument for the key error.
Definition: exceptions.hh:79
An exception class for invalid positions in Utopia::Space.
Definition: exceptions.hh:113
OutOfSpace(const VecT &invalid_pos, const std::shared_ptr< Space > &space, const std::string prefix={})
Construct the exception with the invalid position and the space given.
Definition: exceptions.hh:117
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71
std::string to_string(const Config &node)
Given a config node, returns a string representation of it.
Definition: cfg_utils.hh:110
int handle_exception(exc_t &exc)
A helper function to handle a Utopia-specific exception.
Definition: exceptions.hh:140
Definition: parallel.hh:235