From Jakub Zawadzki via bug #4289: (Fix for) Frame arrival times (pcap)
[obnox/wireshark/wip.git] / epan / exceptions.h
index 100a0fb15192fb6bd61dc6ecd9c247e4d6ec9aec..0b08ad656294206a421c0cff59d069e6e0fcdcd2 100644 (file)
@@ -1,3 +1,27 @@
+/* exceptions.h
+ * Wireshark's exceptions.
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
 #ifndef __EXCEPTIONS_H__
 #define __EXCEPTIONS_H__
 
@@ -8,8 +32,6 @@
 /* Wireshark has only one exception group, to make these macros simple */
 #define XCEPT_GROUP_WIRESHARK 1
 
-/* Wireshark's exceptions */
-
 /**
     Index is out of range.
     An attempt was made to read past the end of a buffer.
@@ -25,7 +47,7 @@
     An attempt was made to read past the logical end of a buffer. This
     differs from a BoundsError in that the parent protocol established a
     limit past which this dissector should not process in the buffer and that
-    limit was execeeded.
+    limit was exceeded.
     This generally means that the packet is invalid, i.e. whatever
     code constructed the packet and put it on the wire didn't put enough
     data into it.  It is therefore currently reported as a "Malformed
@@ -74,7 +96,6 @@
 #define OutOfMemoryError       6
 
 
-
 /* Usage:
  *
  * TRY {
                            * RETHROW, and don't reenter FINALLY if a
                            * different exception is thrown */
 
-#ifdef _MSC_VER
-#define WINTRY __try {
-#define WINENDTRY_BEGIN }  __finally { 
-#define WINENDTRY_END } 
-#else
-#define WINTRY
-#define WINENDTRY_BEGIN 
-#define WINENDTRY_END
-#endif 
-
-#define TRY /**/\
+#define TRY \
 {\
        except_t *exc; \
        volatile int except_state = 0; \
        except_state &= ~EXCEPT_CAUGHT;                \
                                                       \
        if (except_state == 0 && exc == 0)             \
-       WINTRY /* user's code goes here */
-
+               /* user's code goes here */
 
 #define ENDTRY \
-       WINENDTRY_BEGIN /* rethrow the exception if necessary */ \
+       /* rethrow the exception if necessary */ \
        if(!(except_state&EXCEPT_CAUGHT) && exc != 0)  \
            except_rethrow(exc);                 \
-       except_try_pop(); WINENDTRY_END\
+       except_try_pop();\
 }
 
-
 /* the (except_state |= EXCEPT_CAUGHT) in the below is a way of setting
  * except_state before the user's code, without disrupting the user's code if
  * it's a one-liner.
 #define THROW(x) \
        except_throw(XCEPT_GROUP_WIRESHARK, (x), NULL)
 
+#define THROW_ON(cond, x) G_STMT_START { \
+       if ((cond)) \
+               except_throw(XCEPT_GROUP_WIRESHARK, (x), NULL); \
+} G_STMT_END
+
 #define THROW_MESSAGE(x, y) \
        except_throw(XCEPT_GROUP_WIRESHARK, (x), (y))