CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
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
13#include "system/stack_trace.h"
14#include "utility/singleton.h"
15
16#include <cassert>
17#include <functional>
18#include <memory>
19
20namespace CppCommon {
21
23
32class ExceptionsHandler : public CppCommon::Singleton<ExceptionsHandler>
33{
35
36public:
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
65private:
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(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=(ExceptionsHandler &&)=delete
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.
Singleton definition.
Stack trace snapshot provider definition.