From c29ea07138eb1e204fb8f7131fa294817b277f3d Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Wed, 13 Jan 2010 17:41:26 +0100 Subject: [PATCH] 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. --- src/lib/error.c | 16 ++++++++++++++++ src/lib/error.h | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/lib/error.c b/src/lib/error.c index 840288c8d..601b84e47 100644 --- a/src/lib/error.c +++ b/src/lib/error.c @@ -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; +} diff --git a/src/lib/error.h b/src/lib/error.h index 308adf480..1449c4fa2 100644 --- a/src/lib/error.h +++ b/src/lib/error.h @@ -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 */