MLIB
Loading...
Searching...
No Matches
Error Handling

Unified error handling. More...

Classes

class  mlib::checked< T >
 Provides a mechanism similar to expected for creating objects associated with error codes. More...
 
class  mlib::errfac
 An error facility routes a group of errors handled in a similar manner. More...
 
class  mlib::erc
 objects returned as a function result or thrown directly. More...
 

Detailed Description

Unified error handling.

erc objects are a cross between exceptions and return values. A function can return an erc object and the caller can check it just like a regular return value as in this example:

erc func ()
{
return erc(1, erc::error);
}
main () {
if (func() != 1) {
...
}
}

However with erc-s, if the return result is not checked, it might be thrown as an exception as in the following example.

erc func ()
{
return erc(1, erc::error);
}
main () {
try {
func ();
...
}
catch (erc& err) {
printf ("func result %d", (int)err);
}
}

This dual behavior is obtained by having erc objects throwing an exception in their destructor if the object is active. An object is marked as inactive every time the integer conversion operator is invoked like in the first example.

Based on an idea from Marc Guillermont (CUJ 05/2000)