CppCommon  1.0.4.1
C++ Common Library
exceptions_handler.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_ERRORS_EXCEPTIONS_HANDLER_H
10 #define CPPCOMMON_ERRORS_EXCEPTIONS_HANDLER_H
11 
12 #include "filesystem/exceptions.h"
13 #include "system/stack_trace.h"
14 #include "utility/singleton.h"
15 
16 #include <cassert>
17 #include <functional>
18 #include <memory>
19 
20 namespace CppCommon {
21 
23 
32 class ExceptionsHandler : public CppCommon::Singleton<ExceptionsHandler>
33 {
35 
36 public:
40 
43 
45 
51  static void SetupHandler(const std::function<void (const SystemException&, const StackTrace&)>& handler);
53 
57  static void SetupProcess();
59 
63  static void SetupThread();
64 
65 private:
66  class Impl;
67 
68  Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
69  const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
70 
71  static const size_t StorageSize = 72;
72 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
73  static const size_t StorageAlign = 16;
74 #else
75  static const size_t StorageAlign = 8;
76 #endif
77  alignas(StorageAlign) std::byte _storage[StorageSize];
78 
79  ExceptionsHandler();
80 };
81 
84 } // namespace CppCommon
85 
86 #endif // CPPCOMMON_ERRORS_EXCEPTIONS_HANDLER_H
ExceptionsHandler & operator=(ExceptionsHandler &&)=delete
ExceptionsHandler(ExceptionsHandler &&)=delete
static void SetupProcess()
Setup exceptions handler for the current process.
static void SetupHandler(const std::function< void(const SystemException &, const StackTrace &)> &handler)
Setup new global exceptions handler function.
static void SetupThread()
Setup exceptions handler for the current thread.
ExceptionsHandler & operator=(const ExceptionsHandler &)=delete
ExceptionsHandler(const ExceptionsHandler &)=delete
Singleton template base class.
Definition: singleton.h:47
Stack trace snapshot provider.
Definition: stack_trace.h:33
System exception.
Definition: exceptions.h:107
File system exceptions definition.
C++ Common project definitions.
Definition: token_bucket.h:15
Singleton definition.
Stack trace snapshot provider definition.