pytorch/torch/csrc/jit/exception_message.h
Zachary DeVito ea822d9626 Interpreter support for CallFunction/CallMethod (#21562)
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
2019-06-09 15:28:26 -07:00

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