Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't use printf bug logs. Even when raising an error
[simgrid.git] / include / xbt / error.h
index 06a58aa..b8ea1f0 100644 (file)
 
 BEGIN_DECL()
 
-#define _XBT_ERR_PRE do {
-#define _XBT_ERR_POST(code)                                    \
-  return code;                                                 \
-} while (0)
-  
 /** @addtogroup XBT_error 
  *
- *  This is how the errors get reported in the SimGrid toolkit. This mecanism is not 
+ *  This is how the errors get reported in the SimGrid toolkit. This mechanism is not 
  *  as powerful as exceptions, but since we're using C, there is not much we can do.
  *
  *  @{*/
@@ -70,12 +65,10 @@ typedef enum {
 /** @brief return the error code if != no_error
  *  @hideinitializer
  */
-#define TRY(action) do {                                \
-  if ((errcode=action) != no_error) {                   \
-     fprintf (stderr, "%s:%d: '%s' error raising...\n", \
-            __FILE__,__LINE__,                         \
-             xbt_error_name(errcode));                  \
-     return errcode;                                    \
+#define TRY(action) do {                                       \
+  if ((errcode=action) != no_error) {                          \
+     ERROR1("'%s' error raising...", xbt_error_name(errcode)); \
+     return errcode;                                           \
   } } while (0)
    
 /** @brief return the error code if != no_error and != \a catched
@@ -88,9 +81,7 @@ typedef enum {
  */
 #define TRYFAIL(action) do {                                   \
   if ((errcode=action) != no_error) {                          \
-     fprintf(stderr,"%s:%d: Got '%s' error !\n",               \
-            __FILE__,__LINE__,                                \
-             xbt_error_name(errcode));                         \
+     ERROR1("Got '%s' error !", xbt_error_name(errcode));      \
      fflush(stdout);                                           \
      xbt_abort();                                              \
   } } while(0)
@@ -102,7 +93,7 @@ typedef enum {
 #define TRYEXPECT(action,expected_error)  do {                 \
   errcode=action;                                              \
   if (errcode != expected_error) {                             \
-    fprintf(stderr,"Got error %s (instead of %s expected)\n",  \
+    ERROR2("Got error %s (instead of %s expected)\n",          \
            xbt_error_name(errcode),                          \
            xbt_error_name(expected_error));                  \
     xbt_abort();                                              \
@@ -110,6 +101,13 @@ typedef enum {
 } while(0)
 
 /** @}*/
+
+#define _XBT_ERR_PRE do {
+#define _XBT_ERR_POST(code)                                    \
+  return code;                                                 \
+} while (0)
+  
+
 /** @name 3. RAISE macro family
  *
  *  Return a error code, doing some logs on stderr.
@@ -120,42 +118,21 @@ typedef enum {
  */
 
 /** @hideinitializer  */
-#define RAISE0(code,fmt) _XBT_ERR_PRE     \
-  fprintf(stderr,"%s:%d:%s: " fmt "\n",    \
-          __FILE__,__LINE__,__FUNCTION__); \
-  _XBT_ERR_POST(code)
+#define RAISE0(code,fmt)                   _XBT_ERR_PRE   ERROR0(fmt);                   _XBT_ERR_POST(code)
 /** @hideinitializer  */
-#define RAISE1(code,fmt,a1) _XBT_ERR_PRE     \
-  fprintf(stderr,"%s:%d:%s: " fmt "\n",       \
-          __FILE__,__LINE__,__FUNCTION__,a1); \
-  _XBT_ERR_POST(code)
+#define RAISE1(code,fmt,a1)                _XBT_ERR_PRE   ERROR1(fmt,a1);                _XBT_ERR_POST(code)
 /** @hideinitializer  */
-#define RAISE2(code,fmt,a1,a2) _XBT_ERR_PRE     \
-  fprintf(stderr,"%s:%d:%s: " fmt "\n",          \
-          __FILE__,__LINE__,__FUNCTION__,a1,a2); \
-  _XBT_ERR_POST(code)
+#define RAISE2(code,fmt,a1,a2)             _XBT_ERR_PRE   ERROR2(fmt,a1,a2);             _XBT_ERR_POST(code)
 /** @hideinitializer  */
-#define RAISE3(code,fmt,a1,a2,a3) _XBT_ERR_PRE     \
-  fprintf(stderr,"%s:%d:%s: " fmt "\n",             \
-          __FILE__,__LINE__,__FUNCTION__,a1,a2,a3); \
-  _XBT_ERR_POST(code)
+#define RAISE3(code,fmt,a1,a2,a3)          _XBT_ERR_PRE   ERROR3(fmt,a1,a2,a3);          _XBT_ERR_POST(code)
 /** @hideinitializer  */
-#define RAISE4(code,fmt,a1,a2,a3,a4) _XBT_ERR_PRE     \
-  fprintf(stderr,"%s:%d:%s: " fmt "\n",                \
-          __FILE__,__LINE__,__FUNCTION__,a1,a2,a3,a4); \
-  _XBT_ERR_POST(code)
+#define RAISE4(code,fmt,a1,a2,a3,a4)       _XBT_ERR_PRE   ERROR4(fmt,a1,a2,a3,a4);       _XBT_ERR_POST(code)
 /** @hideinitializer  */
-#define RAISE5(code,fmt,a1,a2,a3,a4,a5) _XBT_ERR_PRE     \
-  fprintf(stderr,"%s:%d:%s: " fmt "\n",                   \
-          __FILE__,__LINE__,__FUNCTION__,a1,a2,a3,a4,a5); \
-  _XBT_ERR_POST(code)
+#define RAISE5(code,fmt,a1,a2,a3,a4,a5)    _XBT_ERR_PRE   ERROR5(fmt,a1,a2,a3,a4,a5);    _XBT_ERR_POST(code)
 /** @hideinitializer  */
-#define RAISE6(code,fmt,a1,a2,a3,a4,a5,a6) _XBT_ERR_PRE     \
-  fprintf(stderr,"%s:%d:%s: " fmt "\n",                      \
-          __FILE__,__LINE__,__FUNCTION__,a1,a2,a3,a4,a5,a6); \
-  _XBT_ERR_POST(code)
+#define RAISE6(code,fmt,a1,a2,a3,a4,a5,a6) _XBT_ERR_PRE   ERROR6(fmt,a1,a2,a3,a4,a5,a6); _XBT_ERR_POST(code)
 
-/**@}*/
+/** @} */
 /** 
  * \name 4. assert macro familly
  *
@@ -193,7 +170,7 @@ typedef enum {
 #define xbt_assert6(cond,msg,a,b,c,d,e,f) if (!(cond)) { CRITICAL6(msg,a,b,c,d,e,f); xbt_abort(); }
 #endif
 
-/** @}*/
+/** @} */
 
 /** @name 5. Useful predefined errors 
  *
@@ -205,8 +182,8 @@ typedef enum {
 #define DIE_IMPOSSIBLE xbt_assert0(0,"The Impossible did happen (yet again)")
 #define xbt_assert_error(a) xbt_assert1(errcode == (a), "Error %s unexpected",xbt_error_name(errcode))
 
-/** @}*/
-/**@}*/
+/** @} */
+/** @} */
 
 END_DECL()