From 9667d93cfe7ff7d3952bbd67ce22d724a3d90447 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 3 Jul 2020 20:17:13 +0800 Subject: [PATCH] feat(core): internal changes to exception types See comments. GitOrigin-RevId: ecd3c22faaf425d0e5f11661c2cd9250029f21f6 --- src/core/impl/exception.cpp | 5 ++--- src/core/include/megbrain/exception.h | 11 +++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/impl/exception.cpp b/src/core/impl/exception.cpp index 489be4f8..5e78054f 100644 --- a/src/core/impl/exception.cpp +++ b/src/core/impl/exception.cpp @@ -35,15 +35,14 @@ namespace { MegDNNErrorHandler MegDNNErrorHandler::inst; } -MegBrainError::MegBrainError(const std::string &msg): - m_msg(msg) +void MegBrainError::init() { m_msg.append("\n"); #if MGB_ENABLE_DEBUG_UTIL debug::backtrace(2).fmt_to_str(m_msg); static bool print_exc = MGB_GETENV("MGB_PRINT_EXC"); if (print_exc) { - fprintf(stderr, "mgb: exception occurred: %s\n", msg.c_str()); + fprintf(stderr, "mgb: exception occurred: %s\n", m_msg.c_str()); } #endif } diff --git a/src/core/include/megbrain/exception.h b/src/core/include/megbrain/exception.h index 8af39ba9..7c16e316 100644 --- a/src/core/include/megbrain/exception.h +++ b/src/core/include/megbrain/exception.h @@ -90,7 +90,7 @@ class MegBrainError: public std::exception { virtual ~ExtraInfo() = default; }; - MegBrainError(const std::string &msg); + MegBrainError(const std::string& msg) : m_msg(msg) { init(); } const char *what() const noexcept override { return m_msg.c_str(); @@ -116,6 +116,7 @@ class MegBrainError: public std::exception { private: std::shared_ptr m_extra_info; + void init(); }; //! base class for system error: error caused by uncontrollable environment @@ -188,8 +189,14 @@ class TimeoutError final: public MegBrainError { using MegBrainError::MegBrainError; }; + +} // namespace mgb + +namespace mgb { + bool has_uncaught_exception(); -} // namespace mgb +} // namespace mgb + // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}