MLIB
Loading...
Searching...
No Matches
mlib::erc Class Reference

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.
 
ercoperator= (const erc &rhs)
 Principal assignment operator.
 
ercoperator= (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 errfacfacility () 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
 

Detailed Description

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.

Member Enumeration Documentation

◆ level

Error levels (borrowed from BSD Unix)

Enumerator
none 

always not logged, not thrown

info 

default not logged, not thrown

notice 

default not logged, not thrown

warning 

default logged, not thrown

error 

default logged, thrown

critical 

default logged, thrown

alert 

default logged, thrown

emerg 

always logged, thrown

Constructor & Destructor Documentation

◆ erc()

mlib::erc::erc ( const erc other)
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.

Member Function Documentation

◆ code()

int mlib::erc::code ( ) const
inline

Return numerical value.

As opposed to the integer conversion operator, this function doesn't change the activity flag.

◆ deactivate()

void mlib::erc::deactivate ( ) const
inline

Marks error code as inactive.

Useful in catch clauses when we don't really care what the code value is.

◆ message()

std::string mlib::erc::message ( ) const
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.

◆ operator int()

mlib::erc::operator int ( ) const
inline

Integer conversion operator.

Assume the error has been dealt with and reset the active flag.

◆ operator!=()

bool mlib::erc::operator!= ( const erc other) const
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.

◆ operator=() [1/2]

erc & mlib::erc::operator= ( const erc rhs)
inline

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.

Note
It is rather bad practice to assign to an active erc object. Here we take the view that, since the left side object was already active, we have to deal with it first.

◆ operator=() [2/2]

erc & mlib::erc::operator= ( erc &&  rhs)
inline

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.

◆ operator==()

bool mlib::erc::operator== ( const erc other) const
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.

◆ raise()

void mlib::erc::raise ( ) const
inline

Invoke facility's raise function (errfac::raise) to determine if error code should be logged or thrown


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