/* the machine context */
#if defined(__EX_MCTX_MCSC__)
#include <ucontext.h> /* POSIX.1 ucontext(3) */
/* the machine context */
#if defined(__EX_MCTX_MCSC__)
#include <ucontext.h> /* POSIX.1 ucontext(3) */
*
* This module is a small ISO-C++ style exception handling library
* for use in the ISO-C language. It allows you to use the paradigm
*
* This module is a small ISO-C++ style exception handling library
* for use in the ISO-C language. It allows you to use the paradigm
* These features are brought to you by a modified version of the libex
* library, one of the numerous masterpiece of Ralf S. Engelschall.
*
* These features are brought to you by a modified version of the libex
* library, one of the numerous masterpiece of Ralf S. Engelschall.
*
- * In SimGrid, exceptions is a triple <\a msg , \a category , \a value>
+ * In SimGrid, an exception is a triple <\a msg , \a category , \a value>
* where \a msg is a human-readable text describing the exceptional
* condition, \a code an integer describing what went wrong and \a value
* providing a sort of sub-category. (this is different in the original libex).
* where \a msg is a human-readable text describing the exceptional
* condition, \a code an integer describing what went wrong and \a value
* providing a sort of sub-category. (this is different in the original libex).
* following code which shows some pitfalls and contains many errors (assuming
* a mallocex() function which throws an exception if malloc(3) fails):
*
* following code which shows some pitfalls and contains many errors (assuming
* a mallocex() function which throws an exception if malloc(3) fails):
*
typedef enum {
unknown_error=0, /**< unknown error */
arg_error, /**< Invalid argument */
mismatch_error, /**< The provided ID does not match */
typedef enum {
unknown_error=0, /**< unknown error */
arg_error, /**< Invalid argument */
mismatch_error, /**< The provided ID does not match */
system_error, /**< a syscall did fail */
network_error, /**< error while sending/receiving data */
system_error, /**< a syscall did fail */
network_error, /**< error while sending/receiving data */
- { NULL, 0, { /* content */ NULL, 0, 0, \
+ { NULL, 0, { /* content */ NULL, unknown_error, 0, \
/* throw point*/ NULL, NULL, NULL, 0, NULL,\
/* backtrace */ {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL},0 } }
#define XBT_CTX_INITIALIZE(ctx) \
/* throw point*/ NULL, NULL, NULL, 0, NULL,\
/* backtrace */ {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL},0 } }
#define XBT_CTX_INITIALIZE(ctx) \
(ctx)->ctx_ex.value = 0; \
(ctx)->ctx_ex.host = NULL; \
(ctx)->ctx_ex.procname = NULL; \
(ctx)->ctx_ex.value = 0; \
(ctx)->ctx_ex.host = NULL; \
(ctx)->ctx_ex.procname = NULL; \
/* the termination handler */
typedef void (*ex_term_cb_t)(xbt_ex_t *);
extern ex_term_cb_t __xbt_ex_terminate;
/* the termination handler */
typedef void (*ex_term_cb_t)(xbt_ex_t *);
extern ex_term_cb_t __xbt_ex_terminate;
* The THROW can be performed everywhere, including inside TRY,
* CLEANUP and CATCH blocks.
*/
* The THROW can be performed everywhere, including inside TRY,
* CLEANUP and CATCH blocks.
*/
#define _THROW(c,v,m) \
do { /* change this sequence into one block */ \
/* build the exception */ \
__xbt_ex_ctx()->ctx_ex.msg = (m); \
#define _THROW(c,v,m) \
do { /* change this sequence into one block */ \
/* build the exception */ \
__xbt_ex_ctx()->ctx_ex.msg = (m); \
__xbt_ex_ctx()->ctx_ex.value = (v); \
__xbt_ex_ctx()->ctx_ex.host = (char*)NULL; \
__xbt_ex_ctx()->ctx_ex.procname = strdup(xbt_procname()); \
__xbt_ex_ctx()->ctx_ex.file = (char*)__FILE__; \
__xbt_ex_ctx()->ctx_ex.line = __LINE__; \
__xbt_ex_ctx()->ctx_ex.func = (char*)_XBT_FUNCTION; \
__xbt_ex_ctx()->ctx_ex.value = (v); \
__xbt_ex_ctx()->ctx_ex.host = (char*)NULL; \
__xbt_ex_ctx()->ctx_ex.procname = strdup(xbt_procname()); \
__xbt_ex_ctx()->ctx_ex.file = (char*)__FILE__; \
__xbt_ex_ctx()->ctx_ex.line = __LINE__; \
__xbt_ex_ctx()->ctx_ex.func = (char*)_XBT_FUNCTION; \
/* deal with the exception */ \
if (__xbt_ex_ctx()->ctx_mctx == NULL) \
__xbt_ex_terminate((xbt_ex_t *)&(__xbt_ex_ctx()->ctx_ex)); /* not catched */\
/* deal with the exception */ \
if (__xbt_ex_ctx()->ctx_mctx == NULL) \
__xbt_ex_terminate((xbt_ex_t *)&(__xbt_ex_ctx()->ctx_ex)); /* not catched */\
-#define THROW0(c,v,m) _THROW(c,v,bprintf(m))
+/** @brief Builds and throws an exception with a string taking no arguments
+ @hideinitializer */
+#define THROW0(c,v,m) _THROW(c,v,(m?bprintf(m):NULL))
+/** @brief Builds and throws an exception with a string taking one argument
+ @hideinitializer */
#define THROW1(c,v,m,a1) _THROW(c,v,bprintf(m,a1))
#define THROW1(c,v,m,a1) _THROW(c,v,bprintf(m,a1))
#define THROW2(c,v,m,a1,a2) _THROW(c,v,bprintf(m,a1,a2))
#define THROW2(c,v,m,a1,a2) _THROW(c,v,bprintf(m,a1,a2))
#define THROW3(c,v,m,a1,a2,a3) _THROW(c,v,bprintf(m,a1,a2,a3))
#define THROW3(c,v,m,a1,a2,a3) _THROW(c,v,bprintf(m,a1,a2,a3))
#define THROW4(c,v,m,a1,a2,a3,a4) _THROW(c,v,bprintf(m,a1,a2,a3,a4))
#define THROW4(c,v,m,a1,a2,a3,a4) _THROW(c,v,bprintf(m,a1,a2,a3,a4))
#define THROW5(c,v,m,a1,a2,a3,a4,a5) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5))
#define THROW5(c,v,m,a1,a2,a3,a4,a5) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5))
#define THROW6(c,v,m,a1,a2,a3,a4,a5,a6) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5,a6))
#define THROW_IMPOSSIBLE THROW0(unknown_error,0,"The Impossible Did Happen (yet again)")
#define THROW6(c,v,m,a1,a2,a3,a4,a5,a6) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5,a6))
#define THROW_IMPOSSIBLE THROW0(unknown_error,0,"The Impossible Did Happen (yet again)")
#define THROW_UNIMPLEMENTED THROW1(unknown_error,0,"Function %s unimplemented",__FUNCTION__)
#define THROW_UNIMPLEMENTED THROW1(unknown_error,0,"Function %s unimplemented",__FUNCTION__)
#define RETHROW1(msg,a) _XBT_PRE_RETHROW msg,a, _XBT_POST_RETHROW
#define RETHROW1(msg,a) _XBT_PRE_RETHROW msg,a, _XBT_POST_RETHROW
#define RETHROW2(msg,a,b) _XBT_PRE_RETHROW msg,a,b, _XBT_POST_RETHROW
#define RETHROW2(msg,a,b) _XBT_PRE_RETHROW msg,a,b, _XBT_POST_RETHROW
#define RETHROW3(msg,a,b,c) _XBT_PRE_RETHROW msg,a,b,c, _XBT_POST_RETHROW
#define RETHROW3(msg,a,b,c) _XBT_PRE_RETHROW msg,a,b,c, _XBT_POST_RETHROW
#define RETHROW4(msg,a,b,c,d) _XBT_PRE_RETHROW msg,a,b,c, _XBT_POST_RETHROW
#define RETHROW4(msg,a,b,c,d) _XBT_PRE_RETHROW msg,a,b,c, _XBT_POST_RETHROW
#define RETHROW5(msg,a,b,c,d,e) _XBT_PRE_RETHROW msg,a,b,c,d,e _XBT_POST_RETHROW
#define RETHROW5(msg,a,b,c,d,e) _XBT_PRE_RETHROW msg,a,b,c,d,e _XBT_POST_RETHROW