Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Consider the case of windows context.
[simgrid.git] / include / xbt / ex.h
1 /* $Id$ */
2
3 /* ex - Exception Handling (modified to fit into SimGrid from OSSP version) */
4
5 /*  Copyright (c) 2005-2006 Martin Quinson                                  */
6 /*  Copyright (c) 2002-2004 Ralf S. Engelschall <rse@engelschall.com>       */
7 /*  Copyright (c) 2002-2004 The OSSP Project <http://www.ossp.org/>         */
8 /*  Copyright (c) 2002-2004 Cable & Wireless <http://www.cw.com/>           */
9 /*  All rights reserved.                                                    */
10
11 /* This program is free software; you can redistribute it and/or modify it
12   * under the terms of the license (GNU LGPL) which comes with this package. */
13
14 #ifndef __XBT_EX_H__
15 #define __XBT_EX_H__
16
17 #include <xbt/sysdep.h>
18 #include <xbt/misc.h>
19
20 /* do not include execinfo.h directly since it's not always available. 
21    Instead, copy the parts we need (and fake when it's not there) */
22 extern int backtrace (void **__array, int __size);
23
24 /* required ISO-C standard facilities */
25 #include <errno.h>
26 #include <stdio.h>
27
28
29 /*-*-* Emergency debuging: define this when the exceptions get crazy *-*-*/
30 #undef __EX_MAYDAY
31
32 #ifdef __EX_MAYDAY
33 int gras_os_getpid(void);
34 #  define MAYDAY_SAVE(m)    printf("%d %s:%d save %p\n",                \
35                                    gras_os_getpid(),__FILE__,__LINE__,  \
36                                    (m)->jb                              \
37                                   ),
38 #  define MAYDAY_RESTORE(m) printf("%d %s:%d restore %p\n",             \
39                                    gras_os_getpid(),__FILE__,__LINE__,  \
40                                    (m)->jb                              \
41                                   ),
42 #  define MAYDAY_CATCH(e)   printf("%d %s:%d Catched '%s'\n",           \
43                                    gras_os_getpid(),__FILE__,__LINE__,  \
44                                    e.msg                                \
45                                   ),
46 #else
47 #  define MAYDAY_SAVE(m)
48 #  define MAYDAY_RESTORE(m)
49 #  define MAYDAY_CATCH(e)
50 #endif
51
52 /*-*-* end of debugging stuff *-*-*/
53
54
55 /* the machine context */
56 #if defined(__EX_MCTX_MCSC__)
57 #if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32) && !defined(__TOS_WIN__)
58 #include <ucontext.h>            /* POSIX.1 ucontext(3) */
59 #else
60 #include "xbt/win32_context.h"
61 #endif
62 #include <ucontext.h>            /* POSIX.1 ucontext(3) */
63 #define __ex_mctx_struct         ucontext_t uc;
64 #define __ex_mctx_save(mctx)     (getcontext(&(mctx)->uc) == 0)
65 #define __ex_mctx_restored(mctx) /* noop */
66 #define __ex_mctx_restore(mctx)  (void)setcontext(&(mctx)->uc)
67
68 #elif defined(__EX_MCTX_SSJLJ__)
69 #include <setjmp.h>              /* POSIX.1 sigjmp_buf(3) */
70 #define __ex_mctx_struct         sigjmp_buf jb;
71 #define __ex_mctx_save(mctx)     (sigsetjmp((mctx)->jb, 1) == 0)
72 #define __ex_mctx_restored(mctx) /* noop */
73 #define __ex_mctx_restore(mctx)  (void)siglongjmp((mctx)->jb, 1)
74
75 #elif defined(__EX_MCTX_SJLJ__) || !defined(__EX_MCTX_CUSTOM__) || defined(__EX_MAYDAY)
76 #include <setjmp.h>              /* ISO-C jmp_buf(3) */
77 #define __ex_mctx_struct         jmp_buf jb;
78 #define __ex_mctx_save(mctx)     ( MAYDAY_SAVE(mctx) setjmp((mctx)->jb) == 0)
79 #define __ex_mctx_restored(mctx) /* noop */
80 #define __ex_mctx_restore(mctx)  ( MAYDAY_RESTORE(mctx) (void)longjmp((mctx)->jb, 1))
81 #endif
82
83 /* declare the machine context type */
84 typedef struct { __ex_mctx_struct } __ex_mctx_t;
85
86 /** @addtogroup XBT_ex
87  *  @brief A set of macros providing exception a la C++ in ANSI C (grounding feature)
88  *
89  * This module is a small ISO-C++ style exception handling library
90  * for use in the ISO-C language. It allows you to use the paradigm 
91  * of throwing and catching exceptions in order to reduce the amount
92  * of error handling code without hindering program robustness.
93  *               
94  * This is achieved by directly transferring exceptional return codes
95  * (and the program control flow) from the location where the exception
96  * is raised (throw point) to the location where it is handled (catch
97  * point) -- usually from a deeply nested sub-routine to a parent 
98  * routine. All intermediate routines no longer have to make sure that 
99  * the exceptional return codes from sub-routines are correctly passed 
100  * back to the parent.
101  *
102  * These features are brought to you by a modified version of the libex 
103  * library, one of the numerous masterpiece of Ralf S. Engelschall.
104  *
105  * \htmlonly <div class="toc">\endhtmlonly
106  *
107  * @section XBT_ex_toc TABLE OF CONTENTS
108  *
109  *  - \ref XBT_ex_intro
110  *  - \ref XBT_ex_base
111  *  - \ref XBT_ex_pitfalls
112  *
113  * \htmlonly </div> \endhtmlonly
114  *
115  * @section XBT_ex_intro DESCRIPTION
116  * 
117  * In SimGrid, an exception is a triple <\a msg , \a category , \a value> 
118  * where \a msg is a human-readable text describing the exceptional 
119  * condition, \a code an integer describing what went wrong and \a value
120  * providing a sort of sub-category. (this is different in the original libex).
121  *
122  * @section XBT_ex_base BASIC USAGE
123  *
124  * \em TRY \b TRIED_BLOCK [\em CLEANUP \b CLEANUP_BLOCK] \em CATCH (variable) \b CATCH_BLOCK
125  *
126  * This is the primary syntactical construct provided. It is modeled after the
127  * ISO-C++ try-catch clause and should sound familiar to most of you.
128  *
129  * Any exception thrown directly from the TRIED_BLOCK block or from called
130  * subroutines is caught. Cleanups which must be done after this block
131  * (whenever an exception arised or not) should be placed into the optionnal
132  * CLEANUP_BLOCK. The code dealing with the exceptions when they arise should
133  * be placed into the (mandatory) CATCH_BLOCK.
134  *
135  * 
136  * In absence of exception, the control flow goes into the blocks TRIED_BLOCK
137  * and CLEANUP_BLOCK (if present); The CATCH_BLOCK block is then ignored. 
138  *
139  * When an exception is thrown, the control flow goes through the following
140  * blocks: TRIED_BLOCK (up to the statement throwing the exception),
141  * CLEANUP_BLOCK (if any) and CATCH_BLOCK. The exception is stored in a
142  * variable for inspection inside the CATCH_BLOCK. This variable must be
143  * declared in the outter scope, but its value is only valid within the
144  * CATCH_BLOCK block. 
145  *
146  * Some notes:
147  *  - TRY, CLEANUP and CATCH cannot be used separately, they work
148  *    only in combination and form a language clause as a whole.
149  *  - In contrast to the syntax of other languages (such as C++ or Jave) there
150  *    is only one CATCH block and not multiple ones (all exceptions are
151  *    of the same \em xbt_ex_t C type). 
152  *  - the variable of CATCH can naturally be reused in subsequent 
153  *    CATCH clauses.
154  *  - it is possible to nest TRY clauses.
155  *
156  * The TRY block is a regular ISO-C language statement block, but
157  * 
158  * <center><b>it is not
159  * allowed to jump into it via "goto" or longjmp(3) or out of it via "break",
160  * "return", "goto" or longjmp(3)</b>.</center>
161  *
162  * This is because there is some hidden setup and
163  * cleanup that needs to be done regardless of whether an exception is
164  * caught. Bypassing these steps will break the exception handling facility.
165  * The symptom are likely to be a segfault at the next exception raising point,  
166  * ie far away from the point where you did the mistake. If you suspect
167  * that kind of error in your code, have a look at the little script
168  * <tt>tools/xbt_exception_checker</tt> in the CVS. It extracts all the TRY
169  * blocks from a set of C files you give it and display them (and only
170  * them) on the standard output. You can then grep for the forbidden 
171  * keywords on that output.
172  *   
173  * The CLEANUP and CATCH blocks are regular ISO-C language statement
174  * blocks without any restrictions. You are even allowed to throw (and, in the
175  * CATCH block, to re-throw) exceptions.
176  *
177  * There is one subtle detail you should remember about TRY blocks:
178  * Variables used in the CLEANUP or CATCH clauses must be declared with
179  * the storage class "volatile", otherwise they might contain outdated
180  * information if an exception is thrown.
181  *
182  *
183  * This is because you usually do not know which commands in the TRY
184  * were already successful before the exception was thrown (logically speaking)
185  * and because the underlying ISO-C setjmp(3) facility applies those
186  * restrictions (technically speaking). As a matter of fact, value changes
187  * between the TRY and the THROW may be discarded if you forget the
188  * "volatile" keyword. 
189  * 
190  * \section XBT_ex_pitfalls PROGRAMMING PITFALLS 
191  *
192  * Exception handling is a very elegant and efficient way of dealing with
193  * exceptional situation. Nevertheless it requires additional discipline in
194  * programming and there are a few pitfalls one must be aware of. Look the
195  * following code which shows some pitfalls and contains many errors (assuming
196  * a mallocex() function which throws an exception if malloc(3) fails):
197  *
198  * \dontinclude ex.c
199  * \skip BAD_EXAMPLE
200  * \until end_of_bad_example
201  *
202  * This example raises a few issues:
203  *  -# \b variable \b scope \n
204  *     Variables which are used in the CLEANUP or CATCH clauses must be
205  *     declared before the TRY clause, otherwise they only exist inside the
206  *     TRY block. In the example above, cp1, cp2 and cp3 only exist in the
207  *     TRY block and are invisible from the CLEANUP and CATCH
208  *     blocks.
209  *  -# \b variable \b initialization \n
210  *     Variables which are used in the CLEANUP or CATCH clauses must
211  *     be initialized before the point of the first possible THROW is
212  *     reached. In the example above, CLEANUP would have trouble using cp3
213  *     if mallocex() throws a exception when allocating a TOOBIG buffer.
214  *  -# \b volatile \b variable \n
215  *     Variables which are used in the CLEANUP or CATCH clauses MUST BE
216  *     DECLARED AS "volatile", otherwise they might contain outdated
217  *     information when an exception is thrown. 
218  *  -# \b clean \b before \b catch \n
219  *     The CLEANUP clause is not only place before the CATCH clause in
220  *     the source code, it also occures before in the control flow. So,
221  *     resources being cleaned up cannot be used in the CATCH block. In the
222  *     example, c3 gets freed before the printf placed in CATCH.
223  *  -# \b variable \b uninitialization \n
224  *     If resources are passed out of the scope of the
225  *     TRY/CLEANUP/CATCH construct, they naturally shouldn't get
226  *     cleaned up. The example above does free(3) cp1 in CLEANUP although
227  *     its value was affected to globalcontext->first, invalidating this
228  *     pointer.
229
230  * The following is fixed version of the code (annotated with the pitfall items
231  * for reference): 
232  *
233  * \skip GOOD_EXAMPLE
234  * \until end_of_good_example
235  *
236  * @{
237  */
238
239 /* we need this symbol here, even if it breaks a bit the module separation */
240 long int gras_os_getpid(void);
241
242 /** @brief different kind of errors */
243 typedef enum {
244   unknown_error=0,  /**< unknown error */
245   arg_error,        /**< Invalid argument */
246   mismatch_error,   /**< The provided ID does not match */
247   not_found_error,  /**< The searched element was not found */
248   
249   system_error,   /**< a syscall did fail */
250   network_error,  /**< error while sending/receiving data */
251   timeout_error,  /**< not quick enough, dude */
252   thread_error    /**< error while [un]locking */
253 } xbt_errcat_t;
254
255 const char * xbt_ex_catname(xbt_errcat_t cat);
256
257 /** @brief Structure describing an exception */
258 typedef struct {
259   char        *msg;      /**< human readable message */
260   xbt_errcat_t category; /**< category like HTTP (what went wrong) */
261   int          value;    /**< like errno (why did it went wrong) */
262   /* throw point */
263   short int remote; /**< whether it was raised remotely */
264   char *host;     /**< NULL locally thrown exceptions; full hostname if remote ones */
265   /* FIXME: host should be hostname:port[#thread] */
266   char *procname; /**< Name of the process who thrown this */
267   long int pid;   /**< PID of the process who thrown this */
268   char *file;     /**< Thrown point */
269   int   line;     /**< Thrown point */
270   char *func;     /**< Thrown point */
271   /* Backtrace */
272   int   used;
273   char **bt_strings; /* only filed on display (or before the network propagation) */
274   void *bt[XBT_BACKTRACE_SIZE];
275 } xbt_ex_t;
276
277 /* declare the context type (private) */
278 typedef struct {
279     __ex_mctx_t  *ctx_mctx;     /* permanent machine context of enclosing try/catch */
280     volatile int ctx_caught;    /* temporary flag whether exception was caught */
281     volatile xbt_ex_t ctx_ex;   /* temporary exception storage */
282 } ex_ctx_t;
283
284 /* the static and dynamic initializers for a context structure */
285 #define XBT_CTX_INITIALIZER \
286     { NULL, 0, { /* content */ NULL, unknown_error, 0, \
287                  /* throw point*/ 0,NULL, NULL,0, NULL, 0, NULL,\
288                  /* backtrace */ 0,NULL,{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL} } }
289 #define XBT_CTX_INITIALIZE(ctx) \
290     do { \
291         (ctx)->ctx_mctx          = NULL; \
292         (ctx)->ctx_caught        = 0;    \
293         (ctx)->ctx_ex.msg        = NULL; \
294         (ctx)->ctx_ex.category   = 0;    \
295         (ctx)->ctx_ex.value      = 0;    \
296         (ctx)->ctx_ex.remote     = 0;    \
297         (ctx)->ctx_ex.host       = NULL; \
298         (ctx)->ctx_ex.procname   = NULL; \
299         (ctx)->ctx_ex.pid        = 0;    \
300         (ctx)->ctx_ex.file       = NULL; \
301         (ctx)->ctx_ex.line       = 0;    \
302         (ctx)->ctx_ex.func       = NULL; \
303         (ctx)->ctx_ex.bt[0]      = NULL; \
304         (ctx)->ctx_ex.bt[1]      = NULL; \
305         (ctx)->ctx_ex.bt[2]      = NULL; \
306         (ctx)->ctx_ex.bt[3]      = NULL; \
307         (ctx)->ctx_ex.bt[4]      = NULL; \
308         (ctx)->ctx_ex.bt[5]      = NULL; \
309         (ctx)->ctx_ex.bt[6]      = NULL; \
310         (ctx)->ctx_ex.bt[7]      = NULL; \
311         (ctx)->ctx_ex.bt[8]      = NULL; \
312         (ctx)->ctx_ex.bt[9]      = NULL; \
313         (ctx)->ctx_ex.used       = 0; \
314         (ctx)->ctx_ex.bt_strings = NULL; \
315     } while (0)
316
317 /* the exception context */
318 typedef ex_ctx_t *(*ex_ctx_cb_t)(void);
319 extern ex_ctx_cb_t __xbt_ex_ctx;
320 extern ex_ctx_t *__xbt_ex_ctx_default(void);
321
322 /* the termination handler */
323 typedef void (*ex_term_cb_t)(xbt_ex_t *);
324 extern ex_term_cb_t __xbt_ex_terminate;
325 extern void __xbt_ex_terminate_default(xbt_ex_t *e);
326
327 /** @brief Introduce a block where exception may be dealed with 
328  *  @hideinitializer
329  */
330 #define TRY \
331     { \
332         ex_ctx_t *__xbt_ex_ctx_ptr = __xbt_ex_ctx(); \
333         int __ex_cleanup = 0; \
334         __ex_mctx_t *__ex_mctx_en; \
335         __ex_mctx_t __ex_mctx_me; \
336         __ex_mctx_en = __xbt_ex_ctx_ptr->ctx_mctx; \
337         __xbt_ex_ctx_ptr->ctx_mctx = &__ex_mctx_me; \
338         if (__ex_mctx_save(&__ex_mctx_me)) { \
339             if (1)
340
341 /** @brief optional(!) block for cleanup 
342  *  @hideinitializer
343  */
344 #define CLEANUP \
345             else { \
346             } \
347             __xbt_ex_ctx_ptr->ctx_caught = 0; \
348         } else { \
349             __ex_mctx_restored(&__ex_mctx_me); \
350             __xbt_ex_ctx_ptr->ctx_caught = 1; \
351         } \
352         __xbt_ex_ctx_ptr->ctx_mctx = __ex_mctx_en; \
353         __ex_cleanup = 1; \
354         if (1) { \
355             if (1)
356
357 #ifndef DOXYGEN_SKIP
358 #  ifdef __cplusplus
359 #    define XBT_EX_T_CPLUSPLUSCAST (xbt_ex_t&)
360 #  else
361 #    define XBT_EX_T_CPLUSPLUSCAST 
362 #  endif
363 #endif
364
365 /** @brief the block for catching (ie, deal with) an exception 
366  *  @hideinitializer
367  */
368 #define CATCH(e) \
369             else { \
370             } \
371             if (!(__ex_cleanup)) \
372                 __xbt_ex_ctx_ptr->ctx_caught = 0; \
373         } else { \
374             if (!(__ex_cleanup)) { \
375                 __ex_mctx_restored(&__ex_mctx_me); \
376                 __xbt_ex_ctx_ptr->ctx_caught = 1; \
377             } \
378         } \
379         __xbt_ex_ctx_ptr->ctx_mctx = __ex_mctx_en; \
380     } \
381     if (   !(__xbt_ex_ctx()->ctx_caught) \
382         || ((e) = XBT_EX_T_CPLUSPLUSCAST __xbt_ex_ctx()->ctx_ex, MAYDAY_CATCH(e) 0)) { \
383     } \
384     else
385
386 #define DO_THROW(e) \
387      /* deal with the exception */                                             \
388      if (__xbt_ex_ctx()->ctx_mctx == NULL)                                     \
389        __xbt_ex_terminate((xbt_ex_t *)&(e)); /* not catched */\
390      else                                                                      \
391        __ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx); /* catched somewhere */    \
392      abort()/* nope, stupid GCC, we won't survive a THROW (this won't be reached) */
393
394 /** @brief Helper macro for THROWS0-6
395  *  @hideinitializer
396  *
397  *  @param c: category code (integer)
398  *  @param v: value (integer)
399  *  @param m: message text
400  *
401  * If called from within a TRY/CATCH construct, this exception 
402  * is copied into the CATCH relevant variable program control flow 
403  * is derouted to the CATCH (after the optional sg_cleanup). 
404  *
405  * If no TRY/CATCH construct embeeds this call, the program calls
406  * abort(3). 
407  *
408  * The THROW can be performed everywhere, including inside TRY, 
409  * CLEANUP and CATCH blocks.
410  */
411
412 #define _THROW(c,v,m) \
413   do { /* change this sequence into one block */                              \
414      /* build the exception */                                                \
415      __xbt_ex_ctx()->ctx_ex.msg      = (m);                                   \
416      __xbt_ex_ctx()->ctx_ex.category = (xbt_errcat_t)(c);                     \
417      __xbt_ex_ctx()->ctx_ex.value    = (v);                                   \
418      __xbt_ex_ctx()->ctx_ex.remote   = 0;                                     \
419      __xbt_ex_ctx()->ctx_ex.host     = (char*)NULL;                           \
420      __xbt_ex_ctx()->ctx_ex.procname = (char*)xbt_procname();                 \
421      __xbt_ex_ctx()->ctx_ex.pid      = gras_os_getpid();                      \
422      __xbt_ex_ctx()->ctx_ex.file     = (char*)__FILE__;                       \
423      __xbt_ex_ctx()->ctx_ex.line     = __LINE__;                              \
424      __xbt_ex_ctx()->ctx_ex.func     = (char*)_XBT_FUNCTION;                  \
425      __xbt_ex_ctx()->ctx_ex.used     = backtrace((void**)__xbt_ex_ctx()->ctx_ex.bt,XBT_BACKTRACE_SIZE);\
426      __xbt_ex_ctx()->ctx_ex.bt_strings = NULL; \
427      DO_THROW(__xbt_ex_ctx()->ctx_ex);\
428   } while (0)
429
430 /** @brief Builds and throws an exception with a string taking no arguments
431     @hideinitializer */
432 #define THROW0(c,v,m)                   _THROW(c,v,(m?bprintf(m):NULL))
433 /** @brief Builds and throws an exception with a string taking one argument
434     @hideinitializer */
435 #define THROW1(c,v,m,a1)                _THROW(c,v,bprintf(m,a1))
436 /** @brief Builds and throws an exception with a string taking two arguments
437     @hideinitializer */
438 #define THROW2(c,v,m,a1,a2)             _THROW(c,v,bprintf(m,a1,a2))
439 /** @brief Builds and throws an exception with a string taking three arguments
440     @hideinitializer */
441 #define THROW3(c,v,m,a1,a2,a3)          _THROW(c,v,bprintf(m,a1,a2,a3))
442 /** @brief Builds and throws an exception with a string taking four arguments
443     @hideinitializer */
444 #define THROW4(c,v,m,a1,a2,a3,a4)       _THROW(c,v,bprintf(m,a1,a2,a3,a4))
445 /** @brief Builds and throws an exception with a string taking five arguments
446     @hideinitializer */
447 #define THROW5(c,v,m,a1,a2,a3,a4,a5)    _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5))
448 /** @brief Builds and throws an exception with a string taking six arguments
449     @hideinitializer */
450 #define THROW6(c,v,m,a1,a2,a3,a4,a5,a6) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5,a6))
451 /** @brief Builds and throws an exception with a string taking seven arguments
452     @hideinitializer */
453 #define THROW7(c,v,m,a1,a2,a3,a4,a5,a6,a7) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5,a6,a7))
454
455 #define THROW_IMPOSSIBLE     THROW0(unknown_error,0,"The Impossible Did Happen (yet again)")
456 #define THROW_UNIMPLEMENTED  THROW1(unknown_error,0,"Function %s unimplemented",_XBT_FUNCTION)
457
458 #ifndef NDEBUG
459 #  define DIE_IMPOSSIBLE       xbt_assert0(0,"The Impossible Did Happen (yet again)")
460 #else
461 #  define DIE_IMPOSSIBLE       exit(1);
462 #endif
463
464 /** @brief re-throwing of an already caught exception (ie, pass it to the upper catch block) 
465  *  @hideinitializer
466  */
467 #define RETHROW \
468   do { \
469    if (__xbt_ex_ctx()->ctx_mctx == NULL) \
470      __xbt_ex_terminate((xbt_ex_t *)&(__xbt_ex_ctx()->ctx_ex)); \
471    else \
472      __ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx); \
473    abort();\
474   } while(0)
475
476
477 #ifndef DOXYGEN_SKIP
478 #define _XBT_PRE_RETHROW \
479   do {                                                               \
480     char *_xbt_ex_internal_msg = __xbt_ex_ctx()->ctx_ex.msg;         \
481     __xbt_ex_ctx()->ctx_ex.msg = bprintf(
482 #define _XBT_POST_RETHROW \
483  _xbt_ex_internal_msg); \
484     free(_xbt_ex_internal_msg);                                      \
485     RETHROW;                                                         \
486   } while (0)
487 #endif
488
489 /** @brief like THROW0, but adding some details to the message of an existing exception
490  *  @hideinitializer
491  */
492 #define RETHROW0(msg)           _XBT_PRE_RETHROW msg,          _XBT_POST_RETHROW
493 /** @brief like THROW1, but adding some details to the message of an existing exception
494  *  @hideinitializer
495  */
496 #define RETHROW1(msg,a)         _XBT_PRE_RETHROW msg,a,        _XBT_POST_RETHROW
497 /** @brief like THROW2, but adding some details to the message of an existing exception
498  *  @hideinitializer
499  */
500 #define RETHROW2(msg,a,b)       _XBT_PRE_RETHROW msg,a,b,      _XBT_POST_RETHROW
501 /** @brief like THROW3, but adding some details to the message of an existing exception
502  *  @hideinitializer
503  */
504 #define RETHROW3(msg,a,b,c)     _XBT_PRE_RETHROW msg,a,b,c,    _XBT_POST_RETHROW
505 /** @brief like THROW4, but adding some details to the message of an existing exception
506  *  @hideinitializer
507  */
508 #define RETHROW4(msg,a,b,c,d)   _XBT_PRE_RETHROW msg,a,b,c,d,  _XBT_POST_RETHROW
509 /** @brief like THROW5, but adding some details to the message of an existing exception
510  *  @hideinitializer
511  */
512 #define RETHROW5(msg,a,b,c,d,e) _XBT_PRE_RETHROW msg,a,b,c,d,e, _XBT_POST_RETHROW
513
514 /** @brief Exception destructor */
515 void xbt_ex_free(xbt_ex_t e);
516
517 void xbt_ex_display(xbt_ex_t *e);
518 void xbt_backtrace_display(void);
519
520 /** @} */
521 #endif /* __XBT_EX_H__ */
522