Skip to content

Commit e271d85

Browse files
Yangmei Linfacebook-github-bot
Yangmei Lin
authored andcommitted
Convert multipy embedded library exceptions to specific exception type (#313)
Summary: Pull Request resolved: #313 Convert multipy embedded library exceptions to specific exception type Reviewed By: PaliC Differential Revision: D44477860 fbshipit-source-id: 9cb3d1f17f54a61a79ed9766bcd9377d76a1aea8
1 parent 19617b9 commit e271d85

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

multipy/runtime/Exception.h

+13
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
// This source code is licensed under the BSD-style license found in the
55
// LICENSE file in the root directory of this source tree.
66

7+
#pragma once
8+
79
#ifndef MULTIPY_EXCEPTION_H
810
#define MULTIPY_EXCEPTION_H
911

1012
#include <exception>
13+
#include <stdexcept>
1114

1215
#define MULTIPY_INTERNAL_ASSERT_WITH_MESSAGE(condition, message) \
1316
if (!(condition)) { \
@@ -51,3 +54,13 @@
5154
MULTIPY_CHECK_NO_MESSAGE(__VA_ARGS__));
5255

5356
#endif // MULTIPY_EXCEPTION_H
57+
58+
namespace torch {
59+
namespace deploy {
60+
class MultipyEmbeddedException : public std::runtime_error {
61+
public:
62+
explicit MultipyEmbeddedException(const std::string& error)
63+
: std::runtime_error(error) {}
64+
};
65+
} // namespace deploy
66+
} // namespace torch

multipy/runtime/interpreter/interpreter_impl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ class MultiPySafeRethrow {
9292
auto code = err.value().attr("code").cast<int>();
9393
std::exit(code);
9494
}
95-
throw std::runtime_error(
95+
throw torch::deploy::MultipyEmbeddedException(
9696
std::string(file_) + ":" + std::to_string(line_) +
9797
": Exception Caught inside torch::deploy embedded library: \n" +
9898
err.what());
9999
} catch (std::exception& err) {
100-
throw std::runtime_error(
100+
throw torch::deploy::MultipyEmbeddedException(
101101
std::string(file_) + ":" + std::to_string(line_) +
102102
": Exception Caught inside torch::deploy embedded library: \n" +
103103
err.what());
104104
} catch (...) {
105-
throw std::runtime_error(
105+
throw torch::deploy::MultipyEmbeddedException(
106106
std::string(file_) + ":" + std::to_string(line_) +
107107
": Unknown Exception Caught inside torch::deploy embedded library");
108108
}

0 commit comments

Comments
 (0)