MsPASS C++ API  2.4.1.dev4+g92330b7a
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
mspass::utility::MetadataGetError Class Reference

Error thrown when get operators fail. More...

#include <Metadata.h>

Inheritance diagram for mspass::utility::MetadataGetError:
Inheritance graph
[legend]
Collaboration diagram for mspass::utility::MetadataGetError:
Collaboration graph
[legend]

Public Member Functions

 MetadataGetError ()
 
 MetadataGetError (const std::string key, const char *Texpected)
 
 MetadataGetError (const char *boostmessage, const std::string key, const char *Texpected, const char *Tactual)
 Constructor called when type requested does not match contents.
 
 MetadataGetError (const std::string key, const char *Texpected, const char *Tactual, const std::string detail)
 Constructor called when compatible scalar conversion fails.
 
 MetadataGetError (const MetadataGetError &parent)
 
MetadataGetError operator= (const MetadataGetError &parent)
 
- Public Member Functions inherited from mspass::utility::MsPASSError
 MsPASSError ()
 
 MsPASSError (const std::string mess, const char *howbad)
 Construct from a std::string with badness defined by keywords in a string.
 
 MsPASSError (const std::string mess, const ErrorSeverity s=ErrorSeverity::Invalid)
 
 MsPASSError (const char *mess, const ErrorSeverity s)
 
void log_error ()
 
void log_error (std::ostream &ofs)
 
const char * what () const noexcept
 
ErrorSeverity severity () const
 

Public Attributes

std::stringstream ss
 

Additional Inherited Members

- Protected Attributes inherited from mspass::utility::MsPASSError
std::string message
 
ErrorSeverity badness
 

Detailed Description

Error thrown when get operators fail.

This is a convenience class used to construct a more informative set of errors when get operations fail.

Constructor & Destructor Documentation

◆ MetadataGetError() [1/5]

mspass::utility::MetadataGetError::MetadataGetError ( )
inline

Default constructor used by containers and exception mechanics.

28 : MsPASSError() {}; // seems necessary to not default this with gcc
MsPASSError()
Definition MsPASSError.h:43

◆ MetadataGetError() [2/5]

mspass::utility::MetadataGetError::MetadataGetError ( const std::string  key,
const char *  Texpected 
)
inline

Constructor called when a key is not found in the Metadata.

Parameters
keyis the Metadata key that could not be found.
Texpectedis the type name (return of typeid name method) trying to extract.
33 {
34
35 std::string pretty_name(boost::core::demangle(Texpected));
36 ss << "Error trying to extract Metadata with key=" << key << std::endl
37 << "No value associated with this key is set in Metadata object"
38 << std::endl
39 << "Expected an entry of type=" << pretty_name << std::endl;
40 message = ss.str();
41 badness = ErrorSeverity::Suspect;
42 };
std::stringstream ss
Definition Metadata.h:25
std::string message
Definition MsPASSError.h:108
ErrorSeverity badness
Definition MsPASSError.h:110

References mspass::utility::MsPASSError::badness, mspass::utility::MsPASSError::message, and ss.

◆ MetadataGetError() [3/5]

mspass::utility::MetadataGetError::MetadataGetError ( const char *  boostmessage,
const std::string  key,
const char *  Texpected,
const char *  Tactual 
)
inline

Constructor called when type requested does not match contents.

This implementation uses a pickle style map container where the contents of the map can by any type. We use boost::any to provide sanity checks on types. This is creates the error message thrown when the type of the return does not match the type requested.

50 {
51 ss << "Error in Metadata get method. Type mismatch in attempt to get "
52 << "data with key=" << key << std::endl
53 << "boost::any bad_any_cast wrote this message: " << std::endl
54 << boostmessage << std::endl;
55 std::string name_e(boost::core::demangle(Texpected));
56 ss << "Trying to convert to data of type=" << name_e << std::endl;
57 std::string name_a(boost::core::demangle(Tactual));
58 ss << "Actual entry has type=" << name_a << std::endl;
59 message = ss.str();
60 badness = ErrorSeverity::Suspect;
61 };

References mspass::utility::MsPASSError::badness, mspass::utility::MsPASSError::message, and ss.

◆ MetadataGetError() [4/5]

mspass::utility::MetadataGetError::MetadataGetError ( const std::string  key,
const char *  Texpected,
const char *  Tactual,
const std::string  detail 
)
inline

Constructor called when compatible scalar conversion fails.

This form is used by typed getter wrappers that accept compatible scalar types (for example, integer metadata for a double request), but still need to reject semantic mismatches such as a fractional value for an integer request.

69 {
70 ss << "Error in Metadata get method. Type mismatch in attempt to get "
71 << "data with key=" << key << std::endl;
72 std::string name_e(boost::core::demangle(Texpected));
73 ss << "Trying to convert to data of type=" << name_e << std::endl;
74 std::string name_a(boost::core::demangle(Tactual));
75 ss << "Actual entry has type=" << name_a << std::endl;
76 ss << detail << std::endl;
77 message = ss.str();
78 badness = ErrorSeverity::Suspect;
79 };

References mspass::utility::MsPASSError::badness, mspass::utility::MsPASSError::message, and ss.

◆ MetadataGetError() [5/5]

mspass::utility::MetadataGetError::MetadataGetError ( const MetadataGetError parent)
inline

Copy constructor preserving the message and severity.

81 {
82 message = parent.message;
83 badness = parent.badness;
84 };

References mspass::utility::MsPASSError::badness, and mspass::utility::MsPASSError::message.

Member Function Documentation

◆ operator=()

MetadataGetError mspass::utility::MetadataGetError::operator= ( const MetadataGetError parent)
inline

Assignment operator preserving the message and severity.

86 {
87 if (this != &parent) {
88 message = parent.message;
89 badness = parent.badness;
90 }
91 return *this;
92 };

References mspass::utility::MsPASSError::badness, and mspass::utility::MsPASSError::message.

Member Data Documentation

◆ ss

std::stringstream mspass::utility::MetadataGetError::ss

Stream used internally to assemble the final error message.


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