xref: /aosp_15_r20/external/pytorch/torch/csrc/jit/runtime/jit_exception.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #include <torch/csrc/jit/runtime/jit_exception.h>
2 
3 namespace torch::jit {
4 
5 static thread_local std::string caughtOriginalMsg = "";
6 static thread_local std::string caughtPythonClassName = "";
7 
JITException(const std::string & msg,std::optional<std::string> python_class_name,std::optional<std::string> original_msg)8 JITException::JITException(
9     const std::string& msg,
10     std::optional<std::string> python_class_name,
11     std::optional<std::string> original_msg)
12     : std::runtime_error(msg),
13       python_class_name_(std::move(python_class_name)),
14       original_msg_(std::move(original_msg)) {}
15 
getCaughtOriginalMsg()16 const std::string& JITException::getCaughtOriginalMsg() {
17   return caughtOriginalMsg;
18 }
getCaughtPythonClassName()19 const std::string& JITException::getCaughtPythonClassName() {
20   return caughtPythonClassName;
21 }
setCaughtOriginalMsg(const std::string & msg)22 void JITException::setCaughtOriginalMsg(const std::string& msg) {
23   caughtOriginalMsg = msg;
24 }
setCaughtPythonClassName(const std::string & pythonClassName)25 void JITException::setCaughtPythonClassName(
26     const std::string& pythonClassName) {
27   caughtPythonClassName = pythonClassName;
28 }
29 
30 } // namespace torch::jit
31