suppress_exceptions.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/impl/include_fmtlib.hpp>
#include <restinio/null_logger.hpp>
#include <exception>
namespace restinio
{
namespace utils
{
//
// Wrappers for logging with suppressing of exceptions.
//
template< typename Logger, typename Message_Builder >
void
log_trace_noexcept( Logger && logger, Message_Builder && builder ) noexcept
{
try { logger.trace( std::forward<Message_Builder>(builder) ); }
catch( ... ) {}
}
template< typename Message_Builder >
void
log_trace_noexcept( null_logger_t &, Message_Builder && ) noexcept
{}
template< typename Logger, typename Message_Builder >
void
log_info_noexcept( Logger && logger, Message_Builder && builder ) noexcept
{
try { logger.info( std::forward<Message_Builder>(builder) ); }
catch( ... ) {}
}
template< typename Message_Builder >
void
log_info_noexcept( null_logger_t &, Message_Builder && ) noexcept
{}
template< typename Logger, typename Message_Builder >
void
log_warn_noexcept( Logger && logger, Message_Builder && builder ) noexcept
{
try { logger.warn( std::forward<Message_Builder>(builder) ); }
catch( ... ) {}
}
template< typename Message_Builder >
void
log_warn_noexcept( null_logger_t &, Message_Builder && ) noexcept
{}
template< typename Logger, typename Message_Builder >
void
log_error_noexcept( Logger && logger, Message_Builder && builder ) noexcept
{
try { logger.error( std::forward<Message_Builder>(builder) ); }
catch( ... ) {}
}
template< typename Message_Builder >
void
log_error_noexcept( null_logger_t &, Message_Builder && ) noexcept
{}
template<
typename Logger,
typename Lambda >
void suppress_exceptions(
Logger && logger,
const char * block_description,
Lambda && lambda ) noexcept
{
try
{
lambda();
}
catch( const std::exception & x )
{
log_error_noexcept( logger, [&] {
return fmt::format( "an exception in '{}': {}",
block_description, x.what() );
} );
}
catch( ... )
{
log_error_noexcept( logger, [&] {
return fmt::format( "an unknown exception in '{}'",
block_description );
} );
}
}
template< typename Lambda >
void suppress_exceptions_quietly( Lambda && lambda ) noexcept
{
try
{
lambda();
}
catch( ... ) {}
}
} /* namespace utils */
} /* namespace restinio */
restinio::null_logger_t
No operation logger.
Definition: null_logger.hpp:23
include_fmtlib.hpp
A special wrapper around fmtlib include files.
restinio::utils::suppress_exceptions
void suppress_exceptions(Logger &&logger, const char *block_description, Lambda &&lambda) noexcept
Helper function for execution a block of code with suppression of any exceptions raised inside that b...
Definition: suppress_exceptions.hpp:94
restinio::utils::log_info_noexcept
void log_info_noexcept(Logger &&logger, Message_Builder &&builder) noexcept
Definition: suppress_exceptions.hpp:45
restinio::utils::log_error_noexcept
void log_error_noexcept(Logger &&logger, Message_Builder &&builder) noexcept
Definition: suppress_exceptions.hpp:71
restinio::utils::log_warn_noexcept
void log_warn_noexcept(Logger &&logger, Message_Builder &&builder) noexcept
Definition: suppress_exceptions.hpp:58
restinio::utils::suppress_exceptions_quietly
void suppress_exceptions_quietly(Lambda &&lambda) noexcept
Helper function for execution a block of code with suppression of any exceptions raised inside that b...
Definition: suppress_exceptions.hpp:133
restinio::utils::log_trace_noexcept
void log_trace_noexcept(Logger &&logger, Message_Builder &&builder) noexcept
Definition: suppress_exceptions.hpp:32
restinio
Definition: asio_include.hpp:21
null_logger.hpp