MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / ThrowExceptionToPython

Function ThrowExceptionToPython

paddle/fluid/pybind/exception.cc:91–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91void ThrowExceptionToPython(std::exception_ptr p) {
92 static PyObject* EOFExceptionException =
93 PyErr_NewException("paddle.EOFException", PyExc_Exception, nullptr);
94 static PyObject* EnforceNotMetException =
95 PyErr_NewException("paddle.EnforceNotMet", PyExc_Exception, nullptr);
96 try {
97 if (p) std::rethrow_exception(p);
98 } catch (const platform::EOFException& e) {
99 PyErr_SetString(EOFExceptionException, e.what());
100 } catch (const memory::allocation::BadAlloc& e) {
101 PyErr_SetString(PyExc_MemoryError, e.what());
102 } catch (const platform::EnforceNotMet& e) {
103 switch (e.code()) {
104 case common::ErrorCode::INVALID_ARGUMENT:
105 PyErr_SetString(PyExc_ValueError, e.what());
106 break;
107 case common::ErrorCode::NOT_FOUND:
108 case common::ErrorCode::ALREADY_EXISTS:
109 case common::ErrorCode::PRECONDITION_NOT_MET:
110 case common::ErrorCode::PERMISSION_DENIED:
111 case common::ErrorCode::EXECUTION_TIMEOUT:
112 case common::ErrorCode::UNAVAILABLE:
113 PyErr_SetString(PyExc_RuntimeError, e.what());
114 break;
115 case common::ErrorCode::OUT_OF_RANGE:
116 PyErr_SetString(PyExc_IndexError, e.what());
117 break;
118 case common::ErrorCode::RESOURCE_EXHAUSTED:
119 PyErr_SetString(PyExc_MemoryError, e.what());
120 break;
121 case common::ErrorCode::UNIMPLEMENTED:
122 PyErr_SetString(PyExc_NotImplementedError, e.what());
123 break;
124 case common::ErrorCode::FATAL:
125 PyErr_SetString(PyExc_SystemError, e.what());
126 break;
127 case common::ErrorCode::EXTERNAL:
128 PyErr_SetString(PyExc_OSError, e.what());
129 break;
130 case common::ErrorCode::INVALID_TYPE:
131 PyErr_SetString(PyExc_TypeError, e.what());
132 break;
133 default:
134 PyErr_SetString(EnforceNotMetException, e.what());
135 break;
136 }
137 } catch (const common::PD_Exception& e) {
138 PyErr_SetString(PyExc_OSError, e.what());
139 }
140}
141} // namespace paddle::pybind

Callers 15

static_api_parameterFunction · 0.85
static_api_set_parameterFunction · 0.85
static_api_fullFunction · 0.85
static_api_create_arrayFunction · 0.85
static_api_array_lengthFunction · 0.85
static_api_array_readFunction · 0.85
static_api_fetchFunction · 0.85
static_api_array_write_Function · 0.85

Calls 2

whatMethod · 0.45
codeMethod · 0.45

Tested by

no test coverage detected