Lely core libraries 2.3.4
exception.hpp
Go to the documentation of this file.
1
22#ifndef LELY_UTIL_EXCEPTION_HPP_
23#define LELY_UTIL_EXCEPTION_HPP_
24
25#include <lely/util/errnum.h>
26
27#include <stdexcept>
28#include <system_error>
29
30#ifndef throw_or_abort
35#if __cpp_exceptions
36#define throw_or_abort(e) throw(e)
37#else
38#define throw_or_abort(e) __throw_or_abort((e).what())
39#endif
40#endif
41
42extern "C" {
43
45_Noreturn void __throw_or_abort(const char* what) noexcept;
46}
47
48namespace lely {
49
54class error : public ::std::system_error {
55 public:
56 error(int errc = get_errc())
57 : ::std::system_error(errc, ::std::system_category()), m_errc(errc) {}
58
59 int
60 errc() const noexcept {
61 return m_errc;
62 }
63
65 errnum() const noexcept {
66 return errc2num(errc());
67 }
68
69 private:
70 int m_errc;
71};
72
73} // namespace lely
74
75#endif // !LELY_UTIL_EXCEPTION_HPP_
The type of objects thrown as exceptions to report a system error with an associated error code.
Definition exception.hpp:54
This header file is part of the utilities library; it contains the native and platform-independent er...
errnum_t errc2num(int errc)
Transforms a native error code to a platform-independent error number.
Definition errnum.c:309
errnum
The platform-independent error numbers.
Definition errnum.h:77
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
Definition errnum.c:932
enum errnum errnum_t
The platform-independent error number type.
Definition errnum.h:266
_Noreturn void __throw_or_abort(const char *what) noexcept
Aborts the process instead of throwing an exception.
Definition exception.cpp:36
#define _Noreturn
A function declared with a _Noreturn function specifier SHALL not return to its caller.
Definition features.h:224