-#define THROW(c,v,m) \
- (( __xbt_ex_ctx()->ctx_shielding > 0 \
- || (__xbt_ex_ctx()->ctx_deferring > 0 && __xbt_ex_ctx()->ctx_deferred == 1)) ? 0 : \
- (__xbt_ex_ctx()->ctx_ex.msg = bprintf(m), \
- __xbt_ex_ctx()->ctx_ex.category = (c), \
- __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_deferred = 1, \
- (__xbt_ex_ctx()->ctx_deferring > 0 ? 0 : \
- (__xbt_ex_ctx()->ctx_mctx == NULL \
- ? (__xbt_ex_terminate((ex_t *)&(__xbt_ex_ctx()->ctx_ex)), -1) \
- : (__ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx), 1) ))))
+
+#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.category = (xbt_errcat_t)(c); \
+ __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.used = backtrace((void**)__xbt_ex_ctx()->ctx_ex.bt,XBT_BACKTRACE_SIZE);\
+ /* deal with the exception */ \
+ if (__xbt_ex_ctx()->ctx_mctx == NULL) \
+ __xbt_ex_terminate((xbt_ex_t *)&(__xbt_ex_ctx()->ctx_ex)); /* not catched */\
+ else \
+ __ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx); /* catched somewhere */ \
+ abort();/* nope, stupid GCC, we won't survive a THROW (this won't be reached) */ \
+ } while (0)
+
+/** @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))
+/** @brief Builds and throws an exception with a string taking two arguments
+ @hideinitializer */
+#define THROW2(c,v,m,a1,a2) _THROW(c,v,bprintf(m,a1,a2))
+/** @brief Builds and throws an exception with a string taking three arguments
+ @hideinitializer */
+#define THROW3(c,v,m,a1,a2,a3) _THROW(c,v,bprintf(m,a1,a2,a3))
+/** @brief Builds and throws an exception with a string taking four arguments
+ @hideinitializer */
+#define THROW4(c,v,m,a1,a2,a3,a4) _THROW(c,v,bprintf(m,a1,a2,a3,a4))
+/** @brief Builds and throws an exception with a string taking five arguments
+ @hideinitializer */
+#define THROW5(c,v,m,a1,a2,a3,a4,a5) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5))
+/** @brief Builds and throws an exception with a string taking six arguments
+ @hideinitializer */
+#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__)
+
+#ifndef NDEBUG
+# define DIE_IMPOSSIBLE xbt_assert0(0,"The Impossible Did Happen (yet again)")
+#else
+# define DIE_IMPOSSIBLE exit(1);
+#endif