Prepared release.
[libsex.git] / source / throw.hxx
blob5f67303659fe246af51c403dc36bc870ae42373b
1 /**
2 * @file
4 * Macros related to throwing exceptions.
5 */
7 #ifndef LIBSEX_THROW_HXX
8 #define LIBSEX_THROW_HXX
10 #include <source/utility.hxx>
12 /**
13 * Macro to throw an exception without any argument.
15 * File name and line number are inserted automatically.
17 * @param class Which exception to throw.
19 #define THROW_ARGLESS(class) \
20 { \
21 throw libsex::formatted<class>(__FILE__, __LINE__); \
24 /**
25 * Macro to throw an exception with arguments.
27 * @param class Which exception to throw.
28 * @param args... Arguments for message template.
29 * @see THROW_ARGLESS()
31 #define THROW(class, args...) \
32 { \
33 throw libsex::formatted<class>(__FILE__, __LINE__, ##args); \
36 /**
37 * Macro to throw another exception when an exception has
38 * been caught.
40 * Chains the previous exception and the newly created one
41 * together.
43 * @note The previous exception has to be accessible in
44 * this scope via the variable name @c e.
46 * @param class Which exception to throw.
47 * @param args... Arguments for message template.
48 * @see THROW
50 #define CHAIN(class, args...) \
52 throw libsex::formatted<class>(e, __FILE__, __LINE__, ##args); \
55 #endif