提交 9667d93c 编写于 作者: M Megvii Engine Team

feat(core): internal changes to exception types

See comments.

GitOrigin-RevId: ecd3c22faaf425d0e5f11661c2cd9250029f21f6
上级 c8f3742f
......@@ -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
}
......
......@@ -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<ExtraInfo> 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
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册