version  0.0.1
Defines the C++ API for MsPASS
Public Member Functions | Protected Attributes | List of all members
mspass::utility::MsPASSError Class Reference

Base class for error object thrown by MsPASS library routines. More...

#include <MsPASSError.h>

Inheritance diagram for mspass::utility::MsPASSError:
mspass::utility::AntelopePfError mspass::utility::MetadataGetError mspass::utility::dmatrix_index_error mspass::utility::dmatrix_size_error

Public Member Functions

 MsPASSError ()
 
 MsPASSError (const std::string mess, const char *howbad)
 Construct from a std::string with badness defined by keywords in a string. More...
 
 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
 

Protected Attributes

std::string message
 
ErrorSeverity badness
 

Detailed Description

Base class for error object thrown by MsPASS library routines.

This is the generic error object thrown by the MsPASS library. it is similar in concept to basic error objects described in various books by Stroustrup. The base object contains only a simple generic message and a virtual log_error method common to all MsPASS error objects that are it's descendents.

Author
Gary L. Pavlis

Constructor & Destructor Documentation

◆ MsPASSError() [1/4]

mspass::utility::MsPASSError::MsPASSError ( )
inline

Default constructor built inline.

46  {
47  message="MsPASS library error\n";
48  badness=ErrorSeverity::Fatal;
49  };
std::string message
Definition: MsPASSError.h:109
ErrorSeverity badness
Definition: MsPASSError.h:116

References badness, and message.

◆ MsPASSError() [2/4]

mspass::utility::MsPASSError::MsPASSError ( const std::string  mess,
const char *  howbad 
)
inline

Construct from a std::string with badness defined by keywords in a string.

Sometimes it is easier and more readable to use a string literal to define the error class. This uses that approach.

Parameters
messis the error message posted.
howbadis a string to translate to one of the allowed enum values. The allowed values are the same as the enum defined in this file: FATAL,Invalid,Suspect,Complaint,Debug,Informational.
60  {
61  message=mess;
62  std::string s(howbad);
63  /* this small helper function parses s to conver to the
64  enum class of badness*/
65  badness=string2severity(s);
66  };

References badness, and message.

◆ MsPASSError() [3/4]

mspass::utility::MsPASSError::MsPASSError ( const std::string  mess,
const ErrorSeverity  s = ErrorSeverity::Invalid 
)
inline

Construct from a string with enum defining severity.

This should be the normal form of this error object to throw. Default of the enum allows simpler usage for most errors.

Parameters
mess- is the error message to be posted.
sis the severity enum (default Invalid).
76  {
77  message=mess;
78  badness=s;
79  };

◆ MsPASSError() [4/4]

mspass::utility::MsPASSError::MsPASSError ( const char *  mess,
const ErrorSeverity  s 
)
inline

Construct from a char * and severity enum.

82  {
83  message=std::string(mess);
84  badness=s;
85  };

References badness, and message.

Member Function Documentation

◆ log_error() [1/2]

void mspass::utility::MsPASSError::log_error ( )
inline

Sends error message thrown by MsPASS library functions to standard error.

89  {
90  std::cerr << message << std::endl;
91 };

References message.

◆ log_error() [2/2]

void mspass::utility::MsPASSError::log_error ( std::ostream &  ofs)
inline

Overloaded method for sending error message to other than stderr.

94 {
95  ofs << message <<std::endl;
96 }

References message.

◆ severity()

ErrorSeverity mspass::utility::MsPASSError::severity ( ) const
inline

Return error severity as the enum value.

109 {return badness;};

References badness.

◆ what()

const char* mspass::utility::MsPASSError::what ( ) const
inlinenoexcept

This overrides the method in std::exception to load our string. This allows handlers to use the what method and get the error string from seisp. Idea copied from: http://www.cplusplus.com/doc/tutorial/exceptions/

pybind11 limitations make it problematic for python error handlers to get the output of the severity method or even get to the badness attribute. See the cc code for the implementation detail.

107 {return message.c_str();};

References message.

Member Data Documentation

◆ badness

ErrorSeverity mspass::utility::MsPASSError::badness
protected

Defines the severity of this error - see enum class above

◆ message

std::string mspass::utility::MsPASSError::message
protected

Holds error message that can be printed with log_error method.


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