Browse Source

feat(core): internal changes to exception types

See comments.

GitOrigin-RevId: ecd3c22faa
release-0.6
Megvii Engine Team 5 years ago
parent
commit
9667d93cfe
2 changed files with 11 additions and 5 deletions
  1. +2
    -3
      src/core/impl/exception.cpp
  2. +9
    -2
      src/core/include/megbrain/exception.h

+ 2
- 3
src/core/impl/exception.cpp View File

@@ -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
}


+ 9
- 2
src/core/include/megbrain/exception.h View File

@@ -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
} // namespace mgb


// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

Loading…
Cancel
Save