From b692e101ea7e1aadaf140629b3202cb7624c6d86 Mon Sep 17 00:00:00 2001 From: James Shaw Date: Sat, 22 Sep 2007 12:46:12 +0000 Subject: Implement #defines for try/catch svn path=/trunk/dom/; revision=3565 --- test/testutils.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/testutils.h b/test/testutils.h index e3009af..6e07660 100644 --- a/test/testutils.h +++ b/test/testutils.h @@ -6,7 +6,9 @@ #include #include #include +#include +#include "exceptions.h" #include "utils.h" #include "xmlbinding.h" #include "xmlparser.h" @@ -15,6 +17,31 @@ #define UNUSED(x) ((x) = (x)) #endif +/* Usage: + TRY + THROW(DOM_NOT_FOUND_ERR); + THROW_IF_ERR(dom_document_get_doctype(...)); + CATCH(ex) + printf("exception: %d\n", ex); + ENDTRY +*/ +#define TRY __exvalue=setjmp(__exbuf); \ + if (__exvalue==0) { +#define CATCH(x) } else { \ + int x = __exvalue; +#define ENDTRY } +#define THROW(x) longjmp(__exbuf, x) + +#define THROW_IF_ERR(x) \ + do { \ + int err = x; \ + if (err != DOM_NO_ERR) \ + THROW(err); \ + } while (0) + +jmp_buf __exbuf; +int __exvalue; + /* Redefine assert, so we can simply use the standard assert mechanism * within testcases and exit with the right output for the testrunner * to do the right thing. */ -- cgit v1.2.3