Tech/LxEngine/Errors and Messages

From Athile

Jump to:navigation, search
This page is a work-in-progress. It is not yet complete.
It may contain inaccurate, incorrect information. Use at your own risk.

Notes

80/20 rule. These rules apply in most cases, and if you're not sure, then yes they should. However, there are exceptions: for example, in performance-sensitive code.

5 Levels:

variations:

lx_debug()
lx_message()
lx_log()
lx0::error_exception()
lx0::fatal_exception()

macro lx_error_exception()
macro lx_fatal_exception()

macro lx_assert()
macro lx_check_error()
macro lx_check_fatal()
macro lx_check_warn()

macro lx_assert_not_reentrant();

Error Handling

In non-performance critical code, errors should be handled as exceptions. Return values should be reserved for behavior when the function is executed within it's defined domain.

Individual parts of the code may choose to sub-class error_exception to allow specific types of errors to be caught by different handlers.

The common error handling code should:


Checklist

if something not really expected happens:
 
    if in a destructor:
        Don't throw an exception!!!
        Log a warning
        Handle it as gracefully as possible
        Save critical data if necessary
 
    else 
        switch (what happened)
 
        case A Common, Obvious Error:
        case Something Valid But Nonsensical:
            warning;
 
        case Misuse of the API:
        case Input data malformed:
        case User data doesn't make sense:
        case Parsing Error:
            throw error_exception
 
        case Out of Memory:
            free as much non-critical memory as possible
            throw error_exception;
 
        case Hardware Error:
            possibly retry once or twice;
            salvage system critical data
            throw lx0::fatal_exception
 
        case Threading Error:
        default:
            salvage system critical data
            throw lx0::fatal_exception;
Navigation
Toolbox