Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f598781deb1b36ced72d895ce763e0e686173647
[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 functions 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 SG_BEGIN_DECL()
25
26 /** Helper function used to throw exceptions in C */
27 XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, int value, const char* file, int line, const char* func);
28
29 /** Builds and throws an exception
30  *  @ingroup XBT_ex_c
31  *  @hideinitializer
32  */
33 #define THROW(v) _xbt_throw(NULL, (v), __FILE__, __LINE__, __func__)
34
35 /** Builds and throws an exception with a printf-like formatted message
36  *  @ingroup XBT_ex_c
37  *  @hideinitializer
38  */
39 #define THROWF(v, ...) _xbt_throw(bprintf(__VA_ARGS__), (v), __FILE__, __LINE__, __func__)
40
41 XBT_ATTRIB_NORETURN void xbt_throw_impossible(const char* file, int line, const char* func);
42 /** Throw an exception because something impossible happened
43  *  @ingroup XBT_ex_c
44  */
45 #define THROW_IMPOSSIBLE xbt_throw_impossible(__FILE__, __LINE__, __func__)
46
47 /** Throw an exception because something unimplemented stuff has been attempted
48  *  @ingroup XBT_ex_c
49  */
50 XBT_ATTRIB_NORETURN XBT_PUBLIC void xbt_throw_unimplemented(const char* file, int line, const char* func);
51 #define THROW_UNIMPLEMENTED xbt_throw_unimplemented(__FILE__, __LINE__, __func__)
52
53 /** Die because something impossible happened
54  *  @ingroup XBT_ex_c
55  */
56 #define DIE_IMPOSSIBLE xbt_die("The Impossible Did Happen (yet again)")
57
58 SG_END_DECL()
59
60 /** @} */
61 #endif                          /* __XBT_EX_H__ */