ExceptionHandling.h

Go to the documentation of this file.
00001 /* Copyright (c) 2007, Christian Hujer
00002  * All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *     * Redistributions of source code must retain the above copyright
00007  *       notice, this list of conditions and the following disclaimer.
00008  *     * Redistributions in binary form must reproduce the above copyright
00009  *       notice, this list of conditions and the following disclaimer in the
00010  *       documentation and/or other materials provided with the distribution.
00011  *     * Neither the name of the AceUnit developers nor the
00012  *       names of its contributors may be used to endorse or promote products
00013  *       derived from this software without specific prior written permission.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00016  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00017  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00018  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00019  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00021  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00022  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00024  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00065 #include <setjmp.h>
00066 #include <string.h>
00067 
00077 extern jmp_buf *currentExceptionBuffer;
00078 
00083 #define try \
00084     do { \
00085         int exception; \
00086         jmp_buf lbuf; \
00087         jmp_buf *prev = currentExceptionBuffer; \
00088         currentExceptionBuffer = &lbuf; \
00089         switch (exception = setjmp(lbuf)) { \
00090         case 0: do \
00091 
00092 
00095 #define catch(X) \
00096             while (false); \
00097             break; \
00098         case (X): exception = 0; do \
00099 
00100 
00101 #define catchAll() \
00102             while (false); \
00103             break; \
00104         default: exception = 0; do \
00105 
00106 
00107 #define endtry \
00108             while (false); \
00109         } \
00110         currentExceptionBuffer = prev; \
00111         if (exception) { \
00112             longjmp(*currentExceptionBuffer, exception); \
00113         } \
00114     } while(0)
00115 
00119 #define throw(X) \
00120     do { \
00121         longjmp(*currentExceptionBuffer, (X)); \
00122     } while (false)
00123 
00127 #define rethrow() \
00128     throw(exception)
00129 
00134 #define throws(X)

Generated on Sun Feb 13 11:10:16 2011 for AceUnit by  doxygen 1.5.3