diff --git a/paddle/fluid/imperative/tracer.cc b/paddle/fluid/imperative/tracer.cc index 873963db1a14444a3287771d19efcbee22454706..ee4c5617397b39d6847fecd1c884af8b0e14440f 100644 --- a/paddle/fluid/imperative/tracer.cc +++ b/paddle/fluid/imperative/tracer.cc @@ -53,7 +53,23 @@ void Tracer::TraceOp(const std::string& type, const NameVarBaseMap& ins, attr_checker->Check(&attrs, true); } - OpBase::Run(*op, ins, outs, attrs, place); + try { + OpBase::Run(*op, ins, outs, attrs, place); + } catch (platform::EnforceNotMet& exception) { + framework::AppendErrorOpHint(type, &exception); + throw std::move(exception); + } catch (std::exception& ex) { + PADDLE_THROW(platform::errors::Fatal( + "Operator %s raises an %s exception.\n" + "The exception content is\n:%s.", + type, platform::demangle(typeid(ex).name()), ex.what())); + } catch (...) { + // NOTE: this branch represents a very serious bug with + // low probability of occurrence, and we can't get its + // exception content here. + PADDLE_THROW(platform::errors::Fatal( + "Operator %s raises an unknown exception.", type)); + } if (enable_program_desc_tracing_) { VLOG(5) << "Trace op " << type << " into ProgramDesc";