Logo AND Algorithmique Numérique Distribuée

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