1 /* Copyright (c) 2005-2018. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include <xbt/sysdep.h>
14 #include <xbt/virtu.h>
16 /** @addtogroup XBT_ex_c
17 * @brief Exceptions support (C)
19 * Those fonctions are used to throw C++ exceptions from C code. This feature
20 * should probably be removed in the future because C and exception do not
21 * exactly play nicely together.
24 /** Categories of errors
26 * This very similar to std::error_catgory and should probably be replaced
27 * by this in the future.
32 unknown_error = 0, /**< unknown error */
33 arg_error, /**< Invalid argument */
34 bound_error, /**< Out of bounds argument */
35 mismatch_error, /**< The provided ID does not match */
36 not_found_error, /**< The searched element was not found */
37 system_error, /**< a syscall did fail */
38 network_error, /**< error while sending/receiving data */
39 timeout_error, /**< not quick enough, dude */
40 cancel_error, /**< an action was canceled */
41 thread_error, /**< error while [un]locking */
42 host_error, /**< host failed */
43 tracing_error, /**< error during the simulation tracing */
44 io_error, /**< disk or file error */
45 vm_error /**< vm error */
50 /** Get the name of a category
53 XBT_PUBLIC const char* xbt_ex_catname(xbt_errcat_t cat);
55 typedef struct xbt_ex xbt_ex_t;
57 /** Helper function used to throw exceptions in C */
58 XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, xbt_errcat_t errcat, int value, const char* file,
59 int line, const char* func);
61 /** Builds and throws an exception
65 #define THROW(c, v) { _xbt_throw(NULL, (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__); }
67 /** Builds and throws an exception with a printf-like formatted message
71 #define THROWF(c, v, ...) _xbt_throw(bprintf(__VA_ARGS__), (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__)
73 XBT_ATTRIB_NORETURN void xbt_throw_impossible(const char* file, int line, const char* func);
74 /** Throw an exception because something impossible happened
77 #define THROW_IMPOSSIBLE xbt_throw_impossible(__FILE__, __LINE__, __func__)
79 /** Throw an exception because something unimplemented stuff has been attempted
82 XBT_ATTRIB_NORETURN void xbt_throw_unimplemented(const char* file, int line, const char* func);
83 #define THROW_UNIMPLEMENTED xbt_throw_unimplemented(__FILE__, __LINE__, __func__)
85 /** Die because something impossible happened
88 #define DIE_IMPOSSIBLE xbt_die("The Impossible Did Happen (yet again)")
90 /** Display an exception */
91 XBT_PUBLIC void xbt_ex_display(xbt_ex_t* e);
96 #endif /* __XBT_EX_H__ */