Skip to content

Commit

Permalink
Convert multipy embedded library exceptions to specific exception type (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
Yangmei Lin authored and facebook-github-bot committed Mar 30, 2023
1 parent 19617b9 commit e271d85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions multipy/runtime/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exception>
#include <stdexcept>

#define MULTIPY_INTERNAL_ASSERT_WITH_MESSAGE(condition, message) \
if (!(condition)) { \
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions multipy/runtime/interpreter/interpreter_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ class MultiPySafeRethrow {
auto code = err.value().attr("code").cast<int>();
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");
}
Expand Down

0 comments on commit e271d85

Please sign in to comment.