Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / include / xbt / ex.h
1 /* Copyright (c) 2005-2023. 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
15 /** @addtogroup XBT_ex_c
16  *  @brief Exceptions support (C)
17  *
18  *  Those functions are used to throw C++ exceptions from C code. This feature
19  *  should probably be removed in the future because C and exception do not
20  *  exactly play nicely together.
21  */
22
23 SG_BEGIN_DECL
24
25 /** Helper function used to throw exceptions in C */
26 XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, const char* file, int line, const char* func);
27
28 /** Builds and throws an exception with a printf-like formatted message
29  *  @ingroup XBT_ex_c
30  *  @hideinitializer
31  */
32 #define THROW(...) _xbt_throw(bprintf(__VA_ARGS__), __FILE__, __LINE__, __func__)
33
34 XBT_ATTRIB_NORETURN void xbt_throw_impossible(const char* file, int line, const char* func);
35 /** Throw an exception because something impossible happened
36  *  @ingroup XBT_ex_c
37  */
38 #define THROW_IMPOSSIBLE xbt_throw_impossible(__FILE__, __LINE__, __func__)
39
40 /** Throw an exception because something unimplemented stuff has been attempted
41  *  @ingroup XBT_ex_c
42  */
43 XBT_ATTRIB_NORETURN XBT_PUBLIC void xbt_throw_unimplemented(const char* file, int line, const char* func);
44 #define THROW_UNIMPLEMENTED xbt_throw_unimplemented(__FILE__, __LINE__, __func__)
45
46 /** Die because something impossible happened
47  *  @ingroup XBT_ex_c
48  */
49 #define DIE_IMPOSSIBLE xbt_die("The Impossible Did Happen (yet again)")
50
51 SG_END_DECL
52
53 /** @} */
54 #endif /* XBT_EX_H */