diff --git a/c10/test/util/logging_test.cpp b/c10/test/util/logging_test.cpp index 38f77872891e21..e2bcecaae047b9 100644 --- a/c10/test/util/logging_test.cpp +++ b/c10/test/util/logging_test.cpp @@ -34,7 +34,7 @@ TEST(LoggingTest, TestEnforceEquals) { // This should never be triggered. ADD_FAILURE(); } catch (const ::c10::Error& err) { - EXPECT_NE(err.msg().find("5 vs 6"), string::npos); + EXPECT_NE(std::string(err.what()).find("5 vs 6"), string::npos); } // arguments are expanded only once diff --git a/c10/util/Exception.h b/c10/util/Exception.h index 6b1e77f015f32f..802234b3ecdcae 100644 --- a/c10/util/Exception.h +++ b/c10/util/Exception.h @@ -58,11 +58,6 @@ class C10_API Error : public std::exception { void AppendMessage(const std::string& msg); - // Compute the full message from msg_ and msg_without_backtrace_ - // TODO: Maybe this should be private - std::string msg() const; - std::string msg_without_backtrace() const; - const std::vector& msg_stack() const { return msg_stack_; } @@ -80,6 +75,11 @@ class C10_API Error : public std::exception { const char* what_without_backtrace() const noexcept { return msg_without_backtrace_.c_str(); } + + private: + // Compute the full message from msg_ and msg_without_backtrace_ + std::string msg() const; + std::string msg_without_backtrace() const; }; class C10_API WarningHandler { diff --git a/caffe2/core/operator.cc b/caffe2/core/operator.cc index fe9d4893cc6f70..2105e93e966caa 100644 --- a/caffe2/core/operator.cc +++ b/caffe2/core/operator.cc @@ -580,7 +580,7 @@ TensorShapes InferBlobShapesAndTypes( } } catch (::caffe2::EnforceNotMet& enf) { - LOG(ERROR) << "Shape inference error: " << enf.msg(); + LOG(ERROR) << "Shape inference error: " << enf.what(); LOG(ERROR) << "Operator: " << ProtoDebugString(op) << std::endl; LOG(ERROR) << "Returning empty results."; diff --git a/caffe2/core/operator_test.cc b/caffe2/core/operator_test.cc index f108996e60681e..c890ff29f6a3ca 100644 --- a/caffe2/core/operator_test.cc +++ b/caffe2/core/operator_test.cc @@ -114,14 +114,14 @@ TEST(OperatorTest, ExceptionWorks) { // This should not happen - exception should throw above. LOG(FATAL) << "This should not happen."; } catch (const EnforceNotMet& err) { - LOG(INFO) << err.msg(); + LOG(INFO) << err.what(); } try { op->RunAsync(); // This should not happen - exception should throw above. LOG(FATAL) << "This should not happen."; } catch (const EnforceNotMet& err) { - LOG(INFO) << err.msg(); + LOG(INFO) << err.what(); } } diff --git a/caffe2/mobile/contrib/ios/ios_caffe.cc b/caffe2/mobile/contrib/ios/ios_caffe.cc index 486bf097850a6a..b6724a42f4729c 100644 --- a/caffe2/mobile/contrib/ios/ios_caffe.cc +++ b/caffe2/mobile/contrib/ios/ios_caffe.cc @@ -17,10 +17,6 @@ Caffe2IOSPredictor* MakeCaffe2Predictor(const std::string& init_net_str, try { predictor = Caffe2IOSPredictor::NewCaffe2IOSPredictor( init_net, predict_net, disableMultithreadProcessing, allowMetalOperators); - } catch (const caffe2::EnforceNotMet& e) { - std::string error = e.msg(); - errorMessage.swap(error); - return NULL; } catch (const std::exception& e) { std::string error = e.what(); errorMessage.swap(error); diff --git a/caffe2/mobile/contrib/ios/ios_caffe_predictor.cc b/caffe2/mobile/contrib/ios/ios_caffe_predictor.cc index c2da6617cfcf7a..aa645d31305626 100644 --- a/caffe2/mobile/contrib/ios/ios_caffe_predictor.cc +++ b/caffe2/mobile/contrib/ios/ios_caffe_predictor.cc @@ -57,10 +57,6 @@ void Caffe2IOSPredictor::run(const Tensor& inData, Tensor& outData, std::string& caffe2::Predictor::TensorList output_vec; try { predictor_(input_vec, &output_vec); - } catch (const caffe2::EnforceNotMet& e) { - std::string error = e.msg(); - errorMessage.swap(error); - return; } catch (const std::exception& e) { std::string error = e.what(); errorMessage.swap(error); diff --git a/caffe2/opt/bound_shape_inferencer.cc b/caffe2/opt/bound_shape_inferencer.cc index 3bbd5af4938af9..b9fbe031407756 100644 --- a/caffe2/opt/bound_shape_inferencer.cc +++ b/caffe2/opt/bound_shape_inferencer.cc @@ -820,7 +820,7 @@ void BoundShapeInferencer::InferCommonOp(const OperatorDef& op) { } } catch (const caffe2::EnforceNotMet& e) { LOG(ERROR) << "Enforce not met while inferring shapes for " << op.type() - << ": " << e.msg() << " first output: " << op.output(0); + << ": " << e.what() << " first output: " << op.output(0); } catch (const std::exception& e) { LOG(WARNING) << "Caught exception while inferring shapes for " << op.type() << ": " << e.what() << " first output: " << op.output(0); diff --git a/torch/csrc/jit/runtime/exception_message.h b/torch/csrc/jit/runtime/exception_message.h index 57a2be51d597ed..f2de447d8ac70c 100644 --- a/torch/csrc/jit/runtime/exception_message.h +++ b/torch/csrc/jit/runtime/exception_message.h @@ -20,7 +20,7 @@ inline std::ostream& operator<<( const ExceptionMessage& msg) { auto c10_error = dynamic_cast(&msg.e_); if (c10_error) { - out << c10_error->msg_without_backtrace(); + out << c10_error->what_without_backtrace(); } else { out << msg.e_.what(); }