Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove typedef alias xbt_ex_t.
[simgrid.git] / include / xbt / ex.h
1 /* Copyright (c) 2005-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef XBT_EX_H
7 #define XBT_EX_H
8
9 #include <stdlib.h>
10
11 #include <xbt/base.h>
12 #include <xbt/misc.h>
13 #include <xbt/sysdep.h>
14 #include <xbt/virtu.h>
15
16 /** @addtogroup XBT_ex_c
17  *  @brief Exceptions support (C)
18  *
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.
22  */
23
24 /** Categories of errors
25  *
26  *  This very similar to std::error_catgory and should probably be replaced
27  *  by this in the future.
28  *
29  *  @ingroup XBT_ex_c
30  */
31 typedef enum {
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 */
46 } xbt_errcat_t;
47
48 SG_BEGIN_DECL()
49
50 /** Get the name of a category
51  *  @ingroup XBT_ex_c
52  */
53 XBT_PUBLIC const char* xbt_ex_catname(xbt_errcat_t cat);
54
55 /** Helper function used to throw exceptions in C */
56 XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, xbt_errcat_t errcat, int value, const char* file,
57                                                int line, const char* func);
58
59 /** Builds and throws an exception
60  *  @ingroup XBT_ex_c
61  *  @hideinitializer
62  */
63 #define THROW(c, v)             { _xbt_throw(NULL, (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__); }
64
65 /** Builds and throws an exception with a printf-like formatted message
66  *  @ingroup XBT_ex_c
67  *  @hideinitializer
68  */
69 #define THROWF(c, v, ...)       _xbt_throw(bprintf(__VA_ARGS__), (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__)
70
71 XBT_ATTRIB_NORETURN void xbt_throw_impossible(const char* file, int line, const char* func);
72 /** Throw an exception because something impossible happened
73  *  @ingroup XBT_ex_c
74  */
75 #define THROW_IMPOSSIBLE xbt_throw_impossible(__FILE__, __LINE__, __func__)
76
77 /** Throw an exception because something unimplemented stuff has been attempted
78  *  @ingroup XBT_ex_c
79  */
80 XBT_ATTRIB_NORETURN void xbt_throw_unimplemented(const char* file, int line, const char* func);
81 #define THROW_UNIMPLEMENTED xbt_throw_unimplemented(__FILE__, __LINE__, __func__)
82
83 /** Die because something impossible happened
84  *  @ingroup XBT_ex_c
85  */
86 #define DIE_IMPOSSIBLE xbt_die("The Impossible Did Happen (yet again)")
87
88 SG_END_DECL()
89
90 /** @} */
91 #endif                          /* __XBT_EX_H__ */