Logo AND Algorithmique Numérique Distribuée

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