1 /* Copyright (c) 2005-2018. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include "xbt/sysdep.h"
15 #include "xbt/virtu.h"
17 /** @addtogroup XBT_ex_c
18 * @brief Exceptions support (C)
20 * Those fonctions are used to throw C++ exceptions from C code. This feature
21 * should probably be removed in the future because C and exception do not
22 * exactly play nicely together.
25 /** Categories of errors
27 * This very similar to std::error_catgory and should probably be replaced
28 * by this in the future.
33 unknown_error = 0, /**< unknown error */
34 arg_error, /**< Invalid argument */
35 bound_error, /**< Out of bounds argument */
36 mismatch_error, /**< The provided ID does not match */
37 not_found_error, /**< The searched element was not found */
38 system_error, /**< a syscall did fail */
39 network_error, /**< error while sending/receiving data */
40 timeout_error, /**< not quick enough, dude */
41 cancel_error, /**< an action was canceled */
42 thread_error, /**< error while [un]locking */
43 host_error, /**< host failed */
44 tracing_error, /**< error during the simulation tracing */
45 io_error, /**< disk or file error */
46 vm_error /**< vm error */
51 /** Get the name of a category
54 XBT_PUBLIC const char* xbt_ex_catname(xbt_errcat_t cat);
56 typedef struct xbt_ex xbt_ex_t;
58 /** Helper function used to throw exceptions in C */
59 XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, xbt_errcat_t errcat, int value, const char* file,
60 int line, const char* func);
62 /** Builds and throws an exception
66 #define THROW(c, v) { _xbt_throw(NULL, (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__); }
68 /** Builds and throws an exception with a printf-like formatted message
72 #define THROWF(c, v, ...) _xbt_throw(bprintf(__VA_ARGS__), (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__)
74 /** Throw an exception because someting impossible happened
77 #define THROW_IMPOSSIBLE \
78 THROWF(unknown_error, 0, "The Impossible Did Happen (yet again)")
80 /** Throw an exception because someting unimplemented stuff has been attempted
83 #define THROW_UNIMPLEMENTED \
84 THROWF(unknown_error, 0, "Function %s unimplemented",__func__)
86 /** Throw an exception because some dead code was reached
89 #define THROW_DEADCODE \
90 THROWF(unknown_error, 0, "Function %s was supposed to be DEADCODE, but it's not",__func__)
92 /** Die because something impossible happened
95 #define DIE_IMPOSSIBLE xbt_die("The Impossible Did Happen (yet again)")
97 /** Display an exception */
98 XBT_PUBLIC void xbt_ex_display(xbt_ex_t* e);
103 #endif /* __XBT_EX_H__ */