From a4f60034044e35a0b71f9f8088fce5cea6efa379 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Wed, 3 Jun 2020 15:24:54 +0800 Subject: [PATCH] append try-catch to opbase run, test=develop (#24870) --- paddle/fluid/imperative/tracer.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/imperative/tracer.cc b/paddle/fluid/imperative/tracer.cc index 873963db1a1..ee4c5617397 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"; -- GitLab