3 /* xbt/error.h - Error tracking support */
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #error do not use this crap anymore
15 #include "xbt/misc.h" /* BEGIN_DECL */
20 /** @addtogroup XBT_error
22 * This is how the errors get reported in the SimGrid toolkit. This mechanism is not
23 * as powerful as exceptions, but since we're using C, there is not much we can do.
27 /** @name 1. Type definition and basic operations
31 /** \brief Error types */
33 no_error=0, /**< succes */
34 old_mismatch_error=1, /**< The provided ID does not match */
35 old_system_error=2, /**< a syscall did fail */
36 old_network_error=3, /**< error while sending/receiving data */
37 old_timeout_error=4, /**< not quick enough, dude */
38 old_thread_error=5, /**< error while [un]locking */
39 old_unknown_error=6 /**< unknown error */
43 const char *xbt_error_name(xbt_error_t errcode);
44 void xbt_abort(void) _XBT_GNUC_NORETURN;
45 void xbt_die(const char *msg) _XBT_GNUC_NORETURN;
49 /** @name 2. TRY macro family
51 * Those functions are used to launch a function call and react automatically
52 * to its return value. They expect such a variable to be declared in the scope:
53 * \verbatim xbt_error_t errcode;\endverbatim
57 /** @brief return the error code if != no_error
60 #define TRYOLD(action) do { \
61 if ((errcode=action) != no_error) { \
62 ERROR1("'%s' error raising...", xbt_error_name(errcode)); \
66 /** @brief return the error code if != no_error and != \a catched
69 #define TRYCATCH(action,catched) if ((errcode=action) != no_error && errcode !=catched) return errcode
71 /** @brief xbt_abort if the error code != no_error
74 #define TRYFAIL(action) do { \
75 if ((errcode=action) != no_error) { \
76 ERROR1("Got '%s' error !", xbt_error_name(errcode)); \
82 /** @brief return the error code if != \a expected_error (no_error not ok)
85 #define TRYEXPECT(action,expected_error) do { \
87 if (errcode != expected_error) { \
88 ERROR2("Got error %s (instead of %s expected)\n", \
89 xbt_error_name(errcode), \
90 xbt_error_name(expected_error)); \
97 #define _XBT_ERR_PRE do {
98 #define _XBT_ERR_POST(code) \
103 /** @name 3. RAISE macro family
105 * Return a error code, doing some logs on stderr.
107 * @todo This should use the logging features, not stderr
112 /** @hideinitializer */
113 #define OLDRAISE0(code,fmt) _XBT_ERR_PRE ERROR0(fmt); _XBT_ERR_POST(code)
114 /** @hideinitializer */
115 #define OLDRAISE1(code,fmt,a1) _XBT_ERR_PRE ERROR1(fmt,a1); _XBT_ERR_POST(code)
116 /** @hideinitializer */
117 #define OLDRAISE2(code,fmt,a1,a2) _XBT_ERR_PRE ERROR2(fmt,a1,a2); _XBT_ERR_POST(code)
118 /** @hideinitializer */
119 #define OLDRAISE3(code,fmt,a1,a2,a3) _XBT_ERR_PRE ERROR3(fmt,a1,a2,a3); _XBT_ERR_POST(code)
120 /** @hideinitializer */
121 #define OLDRAISE4(code,fmt,a1,a2,a3,a4) _XBT_ERR_PRE ERROR4(fmt,a1,a2,a3,a4); _XBT_ERR_POST(code)
122 /** @hideinitializer */
123 #define OLDRAISE5(code,fmt,a1,a2,a3,a4,a5) _XBT_ERR_PRE ERROR5(fmt,a1,a2,a3,a4,a5); _XBT_ERR_POST(code)
124 /** @hideinitializer */
125 #define OLDRAISE6(code,fmt,a1,a2,a3,a4,a5,a6) _XBT_ERR_PRE ERROR6(fmt,a1,a2,a3,a4,a5,a6); _XBT_ERR_POST(code)
129 /** @name 5. Useful predefined errors
133 #define RAISE_IMPOSSIBLE RAISE0(old_unknown_error,"The Impossible did happen (yet again)")
134 #define RAISE_UNIMPLEMENTED RAISE1(old_unknown_error,"Function %s unimplemented",__FUNCTION__)
136 #define OLDDIE_IMPOSSIBLE xbt_assert0(0,"The Impossible did happen (yet again)")
137 #define OLDxbt_assert_error(a) xbt_assert1(errcode == (a), "Error %s unexpected",xbt_error_name(errcode))
144 #endif /* XBT_ERROR_H */