lumiera_error_expect() lets one easily handle expected errors
This is a convenience function which clears the error state when some expected error occurred and lets one branch on this.
This commit is contained in:
parent
f0483b1d8b
commit
c29ea07138
2 changed files with 27 additions and 0 deletions
|
|
@ -134,3 +134,19 @@ lumiera_error_peek (void)
|
|||
{
|
||||
return lumiera_error_get ()->err;
|
||||
}
|
||||
|
||||
int
|
||||
lumiera_error_expect (lumiera_err expected)
|
||||
{
|
||||
LumieraErrorcontext self = lumiera_error_get ();
|
||||
lumiera_err err = self->err;
|
||||
|
||||
if (err == expected)
|
||||
{
|
||||
if (err)
|
||||
self->err = NULL;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,6 +160,17 @@ lumiera_err
|
|||
lumiera_error_peek (void);
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param expected error which is expected
|
||||
* @return 1 if the current error state equals the expected state, else 0, the error state is cleared when the expectation is met
|
||||
*/
|
||||
int
|
||||
lumiera_error_expect (lumiera_err expected);
|
||||
|
||||
|
||||
/*
|
||||
predefined errors
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue