From f1f80696ebe87520de0c857371e0ca109fce68cb Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 22 Sep 2007 13:32:42 +0000 Subject: Create a library of utility functions for the testsuite to use Make test/binding.c include stdio.h itself rather than relying on other things to include it. svn path=/trunk/dom/; revision=3568 --- test/lib/exceptions.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/lib/exceptions.h (limited to 'test/lib/exceptions.h') diff --git a/test/lib/exceptions.h b/test/lib/exceptions.h new file mode 100644 index 0000000..1c6b8e2 --- /dev/null +++ b/test/lib/exceptions.h @@ -0,0 +1,34 @@ +#ifndef exceptions_h_ +#define exceptions_h_ + +#include + +#include + +/* 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; + +#endif + -- cgit v1.2.1