/* * SystemException.cpp * * Created on: 8 сент. 2020 г. * Author: LeonidTitov */ #include "SystemException.hh" #include void systemic::ExceptionHandler::handle( const std::exception & exception ) noexcept { if( is_handled ) return; what_happens = exception.what(); const SystemException * system_exception = dynamic_cast( &exception ); std::pair data( nullptr, 0 ); if( system_exception ) { exception_id = system_exception->id(); data = system_exception->binary(); if( buffer.second >= data.second ) std::memcpy( buffer.first, data.first, exception_size = data.second ); } is_handled = true; notify(); } systemic::ExceptionHandler::ExceptionHandler( char * buffer, std::size_t size, NotificationInterface & herald ) : buffer( buffer, size ), herald(herald) {} bool systemic::ExceptionHandler::raised() const { return is_handled; } std::size_t systemic::ExceptionHandler::id() const { return exception_id; } std::pair systemic::ExceptionHandler::binary() const { return { buffer.first, exception_size }; } const char * systemic::ExceptionHandler::description() const { return what_happens; } void systemic::ExceptionHandler::insert( std::size_t id, const char * data, std::size_t size, const char * description ) { exception_id = id; if( size < buffer.second ) std::memcpy( buffer.first, data, exception_size = size ); what_happens = description; is_handled = true; } void systemic::ExceptionHandler::notify() noexcept { try { herald.notify( exception_id, buffer.first, exception_size, what_happens ); } catch( ... ) {} }