lib/error.c File Reference


Detailed Description

C Error handling in Lumiera.

Definition in file error.c.

#include <pthread.h>
#include "lib/error.h"

Include dependency graph for error.c:

Go to the source code of this file.

Classes

struct  lumiera_errorcontext_struct
 Holding error and some context data. More...

Typedefs

typedef struct
lumiera_errorcontext_struct 
lumiera_errorcontext
typedef lumiera_errorcontextLumieraErrorcontext

Functions

lumiera_err lumiera_error (void)
 Get and clear current error state.
 LUMIERA_ERROR_DEFINE (UNKNOWN,"unknown error")
 LUMIERA_ERROR_DEFINE (EERROR,"could not initialize error system")
 LUMIERA_ERROR_DEFINE (ERRNO,"errno")
int lumiera_error_expect (lumiera_err expected)
 Expect some error Check that the current error state matches some expectation, if true then the error state is cleared and 1 is returned, otherwise 0 is returned and the error state remains set.
const char * lumiera_error_extra (void)
 Query the extra context for the last error.
LumieraErrorcontext lumiera_error_get (void)
lumiera_err lumiera_error_peek (void)
 Check current error state without clearing it Please avoid this function and use lumiera_error() if possible.
lumiera_err lumiera_error_set (lumiera_err nerr, const char *extra)
 Set error state for the current thread.
static void lumiera_error_tls_delete (void *err)
static void lumiera_error_tls_init (void)

Variables

static pthread_once_t lumiera_error_initialized = PTHREAD_ONCE_INIT
static pthread_key_t lumiera_error_tls


Function Documentation

lumiera_err lumiera_error_set ( lumiera_err  nerr,
const char *  extra 
)

Set error state for the current thread.

If the error state of the current thread was cleared, then set it, else preserve the old state.

Parameters:
nerr name of the error with 'LUMIERA_ERROR_' prefix (example: LUMIERA_ERROR_NO_MEMORY)
extra a string (possibly a constructed tmpbuf) which adds some more context to the error, can be a temporary
Returns:
old state, that is NULL for success, when the state was cleared and a pointer to a pending error when the error state was already set

Definition at line 96 of file error.c.

lumiera_err lumiera_error ( void   ) 

Get and clear current error state.

This function clears the error state, if it needs to be reused, one has to store it in a temporary variable.

Returns:
pointer to any pending error of this thread, NULL if no error is pending

Definition at line 115 of file error.c.

Referenced by test::Suite::describe(), control::HandlingPattern::invoke(), mobject::session::PlacementIndex::isValid(), lib::advice::Index< POA >::isValid(), lumiera_plugin_init(), lumiera::maybeThrow(), lib::advice::Provision< AD >::storeCopy(), and lumiera::throwOnError().

Here is the caller graph for this function:

const char* lumiera_error_extra ( void   ) 

Query the extra context for the last error.

Returns:
the extra string from the last error

Definition at line 126 of file error.c.

References lumiera_errorcontext_struct::extra.

lumiera_err lumiera_error_peek ( void   ) 

Check current error state without clearing it Please avoid this function and use lumiera_error() if possible.

Errors must be cleared else certain parts of the application refuse to cooperate with you. This shall only be used to decide if one wants to barf out of a loop or subroutine to deliver the error to a higher level.

Returns:
pointer to any pending error of this thread, NULL if no error is pending

Definition at line 133 of file error.c.

References lumiera_errorcontext_struct::err.

Referenced by lumiera_plugin_discover(), and lumiera_plugin_register().

Here is the caller graph for this function:

int lumiera_error_expect ( lumiera_err  expected  ) 

Expect some error Check that the current error state matches some expectation, if true then the error state is cleared and 1 is returned, otherwise 0 is returned and the error state remains set.

Parameters:
expected error which is expected
Returns:
1 if the current error state equals the expected state, else 0, the error state is cleared when the expectation is met

Definition at line 139 of file error.c.


Generated on Sun Aug 1 21:31:13 2010 for Lumiera by  doxygen 1.5.6