78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
/*
|
|
* SystemException.hh
|
|
*
|
|
* Created on: 8 ñåíò. 2020 ã.
|
|
* Author: LeonidTitov
|
|
*/
|
|
|
|
#ifndef UMLIBRARY_SYSTEMIC_SYSTEMEXCEPTION_HH_
|
|
#define UMLIBRARY_SYSTEMIC_SYSTEMEXCEPTION_HH_
|
|
|
|
#include <exception>
|
|
#include <utility>
|
|
#include <cstddef>
|
|
|
|
namespace systemic {
|
|
|
|
struct SystemException : public std::exception {
|
|
virtual std::size_t id() const noexcept = 0;
|
|
virtual std::pair<const char *, std::size_t> binary() const noexcept = 0;
|
|
};
|
|
|
|
struct ExceptionInfo {
|
|
virtual bool raised() const = 0;
|
|
virtual std::size_t id() const = 0;
|
|
virtual std::pair<const char *, std::size_t> binary() const = 0;
|
|
virtual const char * description() const = 0;
|
|
};
|
|
|
|
class ExceptionHandler : public ExceptionInfo {
|
|
public:
|
|
//!Îáðàáîòêà èñêëþ÷åíèÿ.
|
|
void insert( std::size_t id, const char * data, std::size_t size, const char * description );
|
|
|
|
//!Îáðàáîòêà èñêëþ÷åíèÿ.
|
|
void handle( const std::exception & exception ) noexcept;
|
|
void notify() noexcept;
|
|
|
|
struct NotificationInterface {
|
|
virtual void notify( std::size_t id, const char * data, std::size_t size, const char * description ) = 0;
|
|
virtual ~NotificationInterface() = default;
|
|
};
|
|
|
|
static NotificationInterface & getDefault() {
|
|
struct DefaultHerald : public NotificationInterface {
|
|
void notify( std::size_t id, const char * data, std::size_t size, const char * description ) {}
|
|
};
|
|
|
|
static DefaultHerald herald;
|
|
return herald;
|
|
}
|
|
|
|
ExceptionHandler( char * buffer, std::size_t size, NotificationInterface & herald = getDefault() );
|
|
|
|
bool raised() const;
|
|
std::size_t id() const;
|
|
std::pair<const char *, std::size_t> binary() const;
|
|
const char * description() const;
|
|
|
|
private:
|
|
|
|
NotificationInterface & herald;
|
|
|
|
std::size_t exception_id;
|
|
std::size_t exception_size;
|
|
|
|
const std::pair<char *, std::size_t> buffer;
|
|
|
|
const char * what_happens = nullptr;
|
|
|
|
bool is_handled = false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
#endif /* UMLIBRARY_SYSTEMIC_SYSTEMEXCEPTION_HH_ */
|