diff --git a/src/core/impl/exception.cpp b/src/core/impl/exception.cpp index 489be4f898c75631db6a3f96fa32eb27c48a3a7f..5e78054f89255cc5e57245543bbab0c109d4e264 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 8af39ba90612aa709388d0dc53d5cd865ccaee3a..7c16e316e683454538b6db9c09e9cf5c753a3f31 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}}}