quill
QuillError.h
1 
7 #pragma once
8 
9 #include "quill/core/Attributes.h"
10 #include "quill/core/Common.h"
11 
12 #include <exception>
13 #include <string>
14 
15 #if defined(QUILL_NO_EXCEPTIONS)
16  #include <cstdio>
17  #include <cstdlib>
18 
19  #define QUILL_REQUIRE(expression, error) \
20  do \
21  { \
22  if (QUILL_UNLIKELY(!(expression))) \
23  { \
24  printf("Quill fatal error: %s\n", error); \
25  std::abort(); \
26  } \
27  } while (0)
28 
29  #define QUILL_TRY if (true)
30  #define QUILL_THROW(ex) QUILL_REQUIRE(false, ex.what())
31  #define QUILL_CATCH(x) if (false)
32  #define QUILL_CATCH_ALL() if (false)
33 #else
34  #define QUILL_TRY try
35  #define QUILL_THROW(ex) throw(ex)
36  #define QUILL_CATCH(x) catch (x)
37  #define QUILL_CATCH_ALL() catch (...)
38 #endif
39 
40 QUILL_BEGIN_NAMESPACE
41 
42 QUILL_BEGIN_EXPORT
43 
47 class QuillError : public std::exception
48 {
49 public:
50  explicit QuillError(std::string s) : _error(static_cast<std::string&&>(s)) {}
51  explicit QuillError(char const* s) : _error(s) {}
52 
53  QUILL_NODISCARD char const* what() const noexcept override { return _error.c_str(); }
54 
55 private:
56  std::string _error;
57 };
58 
59 QUILL_END_EXPORT
60 
61 QUILL_END_NAMESPACE
custom exception
Definition: QuillError.h:47