diff --git a/multipy/runtime/Exception.h b/multipy/runtime/Exception.h index 2fa9fd5c..0e31a2da 100644 --- a/multipy/runtime/Exception.h +++ b/multipy/runtime/Exception.h @@ -4,10 +4,13 @@ // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. +#pragma once + #ifndef MULTIPY_EXCEPTION_H #define MULTIPY_EXCEPTION_H #include +#include #define MULTIPY_INTERNAL_ASSERT_WITH_MESSAGE(condition, message) \ if (!(condition)) { \ @@ -51,3 +54,13 @@ MULTIPY_CHECK_NO_MESSAGE(__VA_ARGS__)); #endif // MULTIPY_EXCEPTION_H + +namespace torch { +namespace deploy { +class MultipyEmbeddedException : public std::runtime_error { + public: + explicit MultipyEmbeddedException(const std::string& error) + : std::runtime_error(error) {} +}; +} // namespace deploy +} // namespace torch diff --git a/multipy/runtime/interpreter/interpreter_impl.cpp b/multipy/runtime/interpreter/interpreter_impl.cpp index 76e7ace0..f1f2a279 100644 --- a/multipy/runtime/interpreter/interpreter_impl.cpp +++ b/multipy/runtime/interpreter/interpreter_impl.cpp @@ -92,17 +92,17 @@ class MultiPySafeRethrow { auto code = err.value().attr("code").cast(); std::exit(code); } - throw std::runtime_error( + throw torch::deploy::MultipyEmbeddedException( std::string(file_) + ":" + std::to_string(line_) + ": Exception Caught inside torch::deploy embedded library: \n" + err.what()); } catch (std::exception& err) { - throw std::runtime_error( + throw torch::deploy::MultipyEmbeddedException( std::string(file_) + ":" + std::to_string(line_) + ": Exception Caught inside torch::deploy embedded library: \n" + err.what()); } catch (...) { - throw std::runtime_error( + throw torch::deploy::MultipyEmbeddedException( std::string(file_) + ":" + std::to_string(line_) + ": Unknown Exception Caught inside torch::deploy embedded library"); }