mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
Error Handling

How mxlib handles errors

Modules

 Error Codes
 
 Old Error Handling
 
 Error Handling Files
 
 Error Report Verbosity
 
 Internal Error Reporting
 

Macros

#define mx_error_check(fxn)
 Perform an error check on the output of a function.
 
#define mx_error_check_code(errc)
 Perform an error check on an error_t code.
 
#define mx_error_check_rv(fxn, rv)
 Perform an error check on the output of a function.
 
#define mx_error_check_code_rv(errc, rv)
 Perform an error check on an error_t code.
 
#define mx_error_return(fxn)
 Perform an error check on a function and return the result.
 
#define mx_error_return_code(errc)
 Perform an error check on an error_t code and return the result.
 

Functions

bool mx::operator! (const error_t &errc)
 Check if an error_t code is an error.
 
bool mx::operator== (const error_t &errc, bool tf)
 Check if an error_t code is an error.
 
bool mx::operator!= (const error_t &errc, bool tf)
 Check if an error_t code is not an error.
 
bool mx::isError (const error_t &errc)
 Check if an error_t code is an error.
 
template<class verboseT = verbose::d>
std::string mx::error_message (const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
 Format a report given an mxlib error_t code and explanation.
 
template<>
std::string mx::error_message< mx::verbose::o > (const error_t &code, const std::string &expl, const std::source_location &loc)
 Specialization of error_message for verbose::o.
 
template<>
std::string mx::error_message< mx::verbose::v > (const error_t &code, const std::string &expl, const std::source_location &loc)
 Specialization of error_message for verbose::v.
 
template<>
std::string mx::error_message< mx::verbose::vv > (const error_t &code, const std::string &expl, const std::source_location &loc)
 Specialization of error_message for verbose::vv.
 
template<>
std::string mx::error_message< mx::verbose::vvv > (const error_t &code, const std::string &expl, const std::source_location &loc)
 Specialization of error_message for verbose::vvv.
 
template<class verboseT = verbose::vvv>
std::string mx::error_message (const error_t &code, const std::source_location &loc=std::source_location::current())
 Format a report given an mxlib error_t code.
 
template<>
std::string mx::error_message< mx::verbose::o > (const error_t &code, const std::source_location &loc)
 Specialization of error_message for verbose::o.
 
template<>
std::string mx::error_message< mx::verbose::v > (const error_t &code, const std::source_location &loc)
 Specialization of error_message for verbose::v.
 
template<>
std::string mx::error_message< mx::verbose::vv > (const error_t &code, const std::source_location &loc)
 Specialization of error_message for verbose::vv.
 
template<>
std::string mx::error_message< mx::verbose::vvv > (const error_t &code, const std::source_location &loc)
 Specialization of error_message for verbose::vvv.
 
template<class verboseT = verbose::vvv>
error_t mx::error_report (const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
 Print a report to stderr given an mxlib error_t code and explanation and return the code.
 
template<>
error_t mx::error_report< mx::verbose::o > (const error_t &code, const std::string &expl, const std::source_location &loc)
 Specialization of error_report for verbose::o.
 
template<class verboseT = verbose::vvv>
error_t mx::error_report (const error_t &code, const std::source_location &loc=std::source_location::current())
 Print a report to stderr given an mxlib error_t code and return the code.
 
template<>
error_t mx::error_report< mx::verbose::o > (const error_t &code, const std::source_location &loc)
 Specialization of error_report for verbose::o.
 

Macro Definition Documentation

◆ mx_error_check

#define mx_error_check (   fxn)
Value:
{ \
mx::error_t __mxlib_error_check_errc = fxn; \
if( __mxlib_error_check_errc != mx::error_t::noerror ) \
{ \
return error_report<verboseT>( __mxlib_error_check_errc ); \
} \
}
error_t
The mxlib error codes.
Definition error_t.hpp:26
@ noerror
No error has occurred.

Perform an error check on the output of a function.

If an error occurs report it and return the error. Do not return on no error.

Scope protected so the error_t value does not interfere with other values.

Note
this requires that the verbosity template parameter is verboseT
Parameters
fxnis the function to call and check the return value of

Definition at line 613 of file error.hpp.

◆ mx_error_check_code

#define mx_error_check_code (   errc)
Value:
if( errc != mx::error_t::noerror ) \
{ \
return error_report<verboseT>( errc ); \
}

Perform an error check on an error_t code.

If an error is indicated report it and return the error. Do not return on no error.

Note
this requires that the verbosity template parameter is verboseT
Parameters
errcis the code to check for an error value

Definition at line 632 of file error.hpp.

◆ mx_error_check_code_rv

#define mx_error_check_code_rv (   errc,
  rv 
)
Value:
if( errc != mx::error_t::noerror ) \
{ \
error_report<verboseT>( errc ); \
return rv; \
}

Perform an error check on an error_t code.

If an error occurs report it and return an arbitrary type. Does not return on no error. This is intended to be used in int main(), or any other case where the return value is something other than mx::error_t.

Note
this requires that the verbosity template parameter is verboseT
Parameters
errcis the code to check for an error value

Definition at line 673 of file error.hpp.

◆ mx_error_check_rv

#define mx_error_check_rv (   fxn,
  rv 
)
Value:
{ \
mx::error_t __mxlib_error_check_errc = fxn; \
if( __mxlib_error_check_errc != mx::error_t::noerror ) \
{ \
error_report<verboseT>( __mxlib_error_check_errc ); \
return rv; \
} \
}

Perform an error check on the output of a function.

If an error occurs report it and return an arbitrary type. Does not return on no error. This is intended to be used in int main(), or any other case where the return value is something other than mx::error_t.

Scope protected so the mx::error_t value does not interfere with other values.

Note
this requires that the verbosity template parameter is verboseT. You may need to typedef it.
Parameters
fxnis the function to call and check the return value of (can also just be a code).

Definition at line 652 of file error.hpp.

◆ mx_error_return

#define mx_error_return (   fxn)
Value:
{ \
mx::error_t __mx_error_return_errc = fxn; \
if( __mx_error_return_errc != mx::error_t::noerror ) \
{ \
return error_report<verboseT>( __mx_error_return_errc ); \
} \
}

Perform an error check on a function and return the result.

If an error occurs it is reported. If no error occurs error_t::noerror is returned.

Scope protected so the error_t value does not interfere with other values.

Note
this requires that the verbosity template parameter is verboseT
Parameters
fxnis the function to call and check the return value of

Definition at line 692 of file error.hpp.

◆ mx_error_return_code

#define mx_error_return_code (   errc)
Value:
if( errc != mx::error_t::noerror ) \
{ \
return error_report<verboseT>( errc ); \
} \

Perform an error check on an error_t code and return the result.

If an error occurs it is reported and returned. If no error occurs error_t::noerror is returned.

Note
this requires that the verbosity template parameter is verboseT
Parameters
errcis the function to call and check the return value of

Definition at line 712 of file error.hpp.

Function Documentation

◆ error_message() [1/2]

template<class verboseT = verbose::vvv>
std::string mx::error_message ( const error_t code,
const std::source_location &  loc = std::source_location::current() 
)

Format a report given an mxlib error_t code.

What is included depends on the verbosity level set by the template parameter

Template Parameters
verboseTsets the verbosity level based on its level member.
Returns
the formatted message
Parameters
[in]codeis an mx::error_t error code
[in]loc[opt] source location

◆ error_message() [2/2]

template<class verboseT = verbose::d>
std::string mx::error_message ( const error_t code,
const std::string &  expl,
const std::source_location &  loc = std::source_location::current() 
)

Format a report given an mxlib error_t code and explanation.

What is included depends on the verbosity level set by the template parameter

Template Parameters
verboseTsets the verbosity level based on its level member.
Returns
the formatted message
Parameters
[in]codeis an mx::error_t error code
[in]expl[opt] if more information can be provided, use this to inform the user.
[in]loc[opt] source location

Referenced by unitTest::errorTest::errorTest::TEST_CASE().

◆ error_message< mx::verbose::o >() [1/2]

template<>
std::string mx::error_message< mx::verbose::o > ( const error_t code,
const std::source_location &  loc 
)

Specialization of error_message for verbose::o.

◆ error_message< mx::verbose::o >() [2/2]

template<>
std::string mx::error_message< mx::verbose::o > ( const error_t code,
const std::string &  expl,
const std::source_location &  loc 
)

◆ error_message< mx::verbose::v >() [1/2]

template<>
std::string mx::error_message< mx::verbose::v > ( const error_t code,
const std::source_location &  loc 
)

Specialization of error_message for verbose::v.

◆ error_message< mx::verbose::v >() [2/2]

template<>
std::string mx::error_message< mx::verbose::v > ( const error_t code,
const std::string &  expl,
const std::source_location &  loc 
)

◆ error_message< mx::verbose::vv >() [1/2]

template<>
std::string mx::error_message< mx::verbose::vv > ( const error_t code,
const std::source_location &  loc 
)

Specialization of error_message for verbose::vv.

◆ error_message< mx::verbose::vv >() [2/2]

template<>
std::string mx::error_message< mx::verbose::vv > ( const error_t code,
const std::string &  expl,
const std::source_location &  loc 
)

◆ error_message< mx::verbose::vvv >() [1/2]

template<>
std::string mx::error_message< mx::verbose::vvv > ( const error_t code,
const std::source_location &  loc 
)

Specialization of error_message for verbose::vvv.

◆ error_message< mx::verbose::vvv >() [2/2]

template<>
std::string mx::error_message< mx::verbose::vvv > ( const error_t code,
const std::string &  expl,
const std::source_location &  loc 
)

◆ error_report() [1/2]

template<class verboseT = verbose::vvv>
error_t mx::error_report ( const error_t code,
const std::source_location &  loc = std::source_location::current() 
)

Print a report to stderr given an mxlib error_t code and return the code.

What is printed depends on the verbosity level set by the template parameter

Template Parameters
verboseTsets the verbosity level based on its level member.
Returns
the provided error_t code
Parameters
[in]codeis an mx::error_t error code
[in]loc[opt] source location

Definition at line 576 of file error.hpp.

References mx::noerror.

◆ error_report() [2/2]

template<class verboseT = verbose::vvv>
error_t mx::error_report ( const error_t code,
const std::string &  expl,
const std::source_location &  loc = std::source_location::current() 
)

Print a report to stderr given an mxlib error_t code and explanation and return the code.

What is printed depends on the verbosity level set by the template parameter

Template Parameters
verboseTsets the verbosity level based on its level member.
Returns
the provided error_t code
Parameters
[in]codeis an mx::error_t error code
[in]expl[opt] if more information can be provided, use this to inform the user.
[in]loc[opt] source location

Definition at line 540 of file error.hpp.

References mx::noerror.

Referenced by unitTest::errorTest::errorTest::TEST_CASE().

◆ error_report< mx::verbose::o >() [1/2]

template<>
error_t mx::error_report< mx::verbose::o > ( const error_t code,
const std::source_location &  loc 
)

Specialization of error_report for verbose::o.

◆ error_report< mx::verbose::o >() [2/2]

template<>
error_t mx::error_report< mx::verbose::o > ( const error_t code,
const std::string &  expl,
const std::source_location &  loc 
)

◆ isError()

bool mx::isError ( const error_t errc)
inline

Check if an error_t code is an error.

Treats errors as true/false, where false means equal to error_t::noerror and all other values are true.

Parameters
[in]errcthe error_t code to check

Definition at line 120 of file error.hpp.

References mx::noerror.

Referenced by unitTest::errorTest::errorTest::TEST_CASE().

◆ operator!()

bool mx::operator! ( const error_t errc)
inline

Check if an error_t code is an error.

Treats errors as true/false, where false means equal to error_t::noerror and all other values are true. So not returns true if errc is equal to error_t::noerror. So one can use !! to check if an code is an error. Example:

if(!!errc) // will be false, no error
{
//handle errors
}
if(!!errc) // will be true, error
{
//handle errors
}
@ error
A general error has occurred.
Parameters
[in]errcthe error_t code to check

Definition at line 58 of file error.hpp.

References mx::noerror.

Referenced by unitTest::errorTest::errorTest::TEST_CASE().

◆ operator!=()

bool mx::operator!= ( const error_t errc,
bool  tf 
)
inline

Check if an error_t code is not an error.

Treats errors as true/false, where false means equal to error_t::noerror and all other values are true. Example:

if(errc != false) // will be false, no error
{
//handle errors
}
if(errc != false) // will be true, error
{
//handle errors
}
Parameters
[in]errcthe error_t code to check
[in]tfthe value to compare to

Definition at line 108 of file error.hpp.

References mx::noerror.

Referenced by mx::math::operator!=(), and unitTest::errorTest::errorTest::TEST_CASE().

◆ operator==()

bool mx::operator== ( const error_t errc,
bool  tf 
)
inline

Check if an error_t code is an error.

Treats errors as true/false, where false means equal to error_t::noerror and all other values are true. Example:

if(errc == true) // will be false, no error
{
//handle errors
}
if(errc == true) // will be true, error
{
//handle errors
}
Parameters
[in]errcthe error_t code to check
[in]tfthe value to compare to

Definition at line 82 of file error.hpp.

References mx::noerror.

Referenced by mx::math::operator==(), and unitTest::errorTest::errorTest::TEST_CASE().