Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
Utopia::KeyError Class Reference

For access to a dict-like structure with a bad key. More...

#include <exceptions.hh>

Inheritance diagram for Utopia::KeyError:
Inheritance graph
[legend]
Collaboration diagram for Utopia::KeyError:
Collaboration graph
[legend]

Public Member Functions

 KeyError (const std::string &key, const DataIO::Config &node, const std::string &prefix="")
 Construct a KeyError exception, which has a standardized what message.
 
- Public Member Functions inherited from Utopia::Exception
 Exception (const std::string &what_arg, const int exit_code_arg=1)
 Construct an Utopia-specific exception.
 
 Exception (const char *what_arg, const int exit_code_arg=1)
 Construct an Utopia-specific exception.
 

Private Member Functions

std::string generate_what_arg (std::string key, DataIO::Config node, std::string prefix)
 Generates the what argument for the key error.
 

Additional Inherited Members

- Public Attributes inherited from Utopia::Exception
const int exit_code
 The exit code to use when exiting due to this exception.
 

Detailed Description

For access to a dict-like structure with a bad key.

Constructor & Destructor Documentation

◆ KeyError()

Utopia::KeyError::KeyError ( const std::string &  key,
const DataIO::Config node,
const std::string &  prefix = "" 
)
inline

Construct a KeyError exception, which has a standardized what message.

73 :
75 {}
Exception(const std::string &what_arg, const int exit_code_arg=1)
Construct an Utopia-specific exception.
Definition exceptions.hh:26
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
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

Member Function Documentation

◆ generate_what_arg()

std::string Utopia::KeyError::generate_what_arg ( std::string  key,
DataIO::Config  node,
std::string  prefix 
)
inlineprivate

Generates the what argument for the key error.

82 {
83 std::stringstream msg;
84
85 if (prefix.length()) {
86 msg << prefix << std::endl;
87 }
88
89 msg << "KeyError: " << key << std::endl;
90
91 if (not node) {
92 msg << "The given node is a Zombie! Make sure the node you are "
93 << "trying to read from is valid." << std::endl;
94 }
95 else if (node.size() == 0) {
96 msg << "The given node contains no entries! Make sure the desired "
97 << "key is available."
98 << std::endl;
99 }
100 else {
101 // Emit the node to give more clues at what might have gone wrong
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;
105 }
106
107 return msg.str();
108 }

The documentation for this class was generated from the following file: