#pragma once #include "tl/detail/prologue.h" /////////////////////////////////////////////////////////////////////////////// // namespace tl { namespace crash { //use this to specify a function to be called when a crash is requested. //Note!!! File and msg can be NULL //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // // It's very risky to implement this function so do it only if you REALLY REALLY have to do something before the crash. // This might be called because the system is out of memory - so any allocation will fail. Same for file handles or any other resources. // //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! enum class response { CRASH, CONTINUE }; using handler = response (*)(const char *, int, const char *); TL_API handler set_handler(handler) noexcept; TL_API response default_handler(const char* file, int line, const char* msg) noexcept; //Use this to temporarily change the assert handler for the current scope class handler_guard { public: explicit handler_guard(handler new_handler) noexcept { m_prev_handler = set_handler(new_handler); } ~handler_guard() noexcept { set_handler(m_prev_handler); } private: handler m_prev_handler; }; /////////////////////////////////////////////////////////////////////// //for internal use only namespace detail { TL_API handler& get_static_handler() noexcept; //this is responsible of formatting the messages and calling the handler inline response invoke_crash_handler(const char* file, int line, const char* msg) noexcept { const handler& handler = get_static_handler(); return handler(file, line, msg); } } } } #include "tl/detail/internal_assert.h"