mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/21562 ghimport-source-id: 17e5e183f730f50d97ef48973aafc6249d54978f Reviewed By: suo Differential Revision: D15729500 Pulled By: zdevito fbshipit-source-id: efa8a133b617b1498810392a8da6b513ce00b5eb
32 lines
638 B
C++
32 lines
638 B
C++
#pragma once
|
|
#include <c10/util/Exception.h>
|
|
#include <stdexcept>
|
|
|
|
namespace torch {
|
|
namespace jit {
|
|
|
|
struct ExceptionMessage {
|
|
ExceptionMessage(const std::exception& e) : e_(e) {}
|
|
|
|
private:
|
|
const std::exception& e_;
|
|
friend std::ostream& operator<<(
|
|
std::ostream& out,
|
|
const ExceptionMessage& msg);
|
|
};
|
|
|
|
inline std::ostream& operator<<(
|
|
std::ostream& out,
|
|
const ExceptionMessage& msg) {
|
|
auto c10_error = dynamic_cast<const c10::Error*>(&msg.e_);
|
|
if (c10_error) {
|
|
out << c10_error->msg_without_backtrace();
|
|
} else {
|
|
out << msg.e_.what();
|
|
}
|
|
return out;
|
|
}
|
|
|
|
} // namespace jit
|
|
} // namespace torch
|