Skip to content

File exceptions.hpp

File List > backends > cxx > include > zmbt > core > exceptions.hpp

Go to the documentation of this file

#ifndef ZMBT_CORE_EXCEPTIONS_HPP_
#define ZMBT_CORE_EXCEPTIONS_HPP_


#include <boost/throw_exception.hpp>

#include "format_string.hpp"
#include "type_info.hpp"

namespace zmbt {

struct base_error : public std::runtime_error {
    using std::runtime_error::runtime_error;

    template <class... A>
    base_error(boost::json::string_view fmtstr, A&&... args) : std::runtime_error(format(fmtstr, std::forward<A>(args)...))
    {
    }
};


struct serialization_error : public base_error {
    using base_error::base_error;
};

struct environment_error : public base_error {
    using base_error::base_error;
};



namespace detail
{
    void log_exception(char const* type, char const* what);
}

template <class E>
void throw_exception(E&& e)
{
    // auto const dynamic_exception_type = boost::typeindex::type_id_runtime(e).pretty_name();
    detail::log_exception(type_name(e).c_str(), e.what());
    boost::throw_exception(std::forward<E>(e));
}

}  // namespace zmbt

#endif