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 (%s:%d)\n", error, QUILL_FILE_NAME, QUILL_LINE_NO); \
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 
45 class QuillError : public std::exception
46 {
47 public:
48  explicit QuillError(std::string s) : _error(static_cast<std::string&&>(s)) {}
49  explicit QuillError(char const* s) : _error(s) {}
50 
51  QUILL_NODISCARD char const* what() const noexcept override { return _error.data(); }
52 
53 private:
54  std::string _error;
55 };
56 
57 QUILL_END_NAMESPACE
custom exception
Definition: QuillError.h:45