MLIB
|
objects returned as a function result or thrown directly. More...
#include <errorcode.h>
Public Types | |
enum | level { none = 0 , info , notice , warning , error , critical , alert , emerg } |
Error levels (borrowed from BSD Unix) More... | |
Public Member Functions | |
erc () | |
Default ctor for erc objects creates an inactive error. | |
erc (int value, level priority=level::error) | |
Ctor for a real erc using default error facility. | |
erc (int value, const mlib::errfac &facility, level priority=level::error) | |
Ctor for a real erc. | |
erc (const erc &other) | |
Copy constructor removes the activity flag of the original object. | |
erc (erc &&other) | |
Move constructor removes the activity flag of the original object. | |
~erc () noexcept(false) | |
Destructor. Call raise() function to see if the error should get logged or thrown. | |
erc & | operator= (const erc &rhs) |
Principal assignment operator. | |
erc & | operator= (erc &&rhs) |
Move assignment operator. | |
operator int () const | |
Integer conversion operator. | |
level | priority () const |
Return priority value. | |
bool | is_active () const |
Return activity flag. | |
const errfac & | facility () const |
Return reference to facility. | |
bool | operator== (const erc &other) const |
Equality comparison operator. | |
bool | operator!= (const erc &other) const |
Inequality comparison operator. | |
void | raise () const |
void | reactivate () const |
Similar to re-throwing an exception. | |
void | deactivate () const |
Marks error code as inactive. | |
int | code () const |
Return numerical value. | |
std::string | message () const |
Get logging message. | |
void | message (const std::string &m) |
Set the message for this error. | |
Static Public Attributes | |
static erc | success {0, erc::none} |
The SUCCESS indicator. | |
Friends | |
class | errfac |
objects returned as a function result or thrown directly.
If not tested and their level is above facility's logging level they will be logged (by calling errfac::log() ). If the level is above facility's throwing level they will be thrown as exceptions.
enum mlib::erc::level |
Error levels (borrowed from BSD Unix)
|
inline |
Copy constructor removes the activity flag of the original object.
Having two erc's active at the same time is a big no-no: when one of them is thrown, the stack unwinding process invokes the destructor of the other one, which in turn might throw again. Throwing an exception during stack unwinding will terminate your application. For more details see: https://isocpp.org/wiki/faq/exceptions#dtors-shouldnt-throw
However, the whole concept of erc's is based upon destructors throwing exceptions. Here we carefully navigate between a rock and a hard place.
|
inline |
Return numerical value.
As opposed to the integer conversion operator, this function doesn't change the activity flag.
|
inline |
Marks error code as inactive.
Useful in catch clauses when we don't really care what the code value is.
|
inline |
Get logging message.
Return message string associated this error.
If no message string has been attached to this object, it calls errfac::message() function to generate the message string.
|
inline |
Integer conversion operator.
Assume the error has been dealt with and reset the active flag.
|
inline |
Inequality comparison operator.
All success codes are equal. Other codes are equal only if their value, level and facility are equal.
Resets the activity flag.
Principal assignment operator.
If we were active before, call the facility to log or throw. Anyhow copy new values from the assigned object and take away it's active flag.
erc
object. Here we take the view that, since the left side object was already active, we have to deal with it first. Move assignment operator.
If we were active before, call the facility to log or throw. Anyhow copy new values from the assigned object and take away it's active flag.
|
inline |
Equality comparison operator.
All success codes are equal. Other codes are equal only if their value, level and facility are equal.
Resets the activity flag.
|
inline |
Invoke facility's raise function (errfac::raise) to determine if error code should be logged or thrown