Lely core libraries  2.2.5
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
31 
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 
42 extern "C" {
43 
45 _Noreturn void __throw_or_abort(const char* what) noexcept;
46 }
47 
48 namespace lely {
49 
54 class 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 
64  errnum_t
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_
get_errc
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
Definition: errnum.c:947
lely::error
The type of objects thrown as exceptions to report a system error with an associated error code.
Definition: exception.hpp:54
_Noreturn
#define _Noreturn
A function declared with a _Noreturn function specifier SHALL not return to its caller.
Definition: features.h:214
__throw_or_abort
_Noreturn void __throw_or_abort(const char *what) noexcept
Aborts the process instead of throwing an exception.
Definition: exception.cpp:36
errnum
errnum
The platform-independent error numbers.
Definition: errnum.h:74
errnum.h
errc2num
errnum_t errc2num(int errc)
Transforms a native error code to a platform-independent error number.
Definition: errnum.c:310
errnum_t
enum errnum errnum_t
The platform-independent error number type.
Definition: errnum.h:263