File tree Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -487,25 +487,22 @@ void Shell::handle_error()
487487void Shell::handle_error (py::error_already_set& err)
488488 {
489489 if (err.matches (PyExc_SystemExit)) {
490- std::cerr << " SystemExit" << std::endl;
491490 auto value = err.value ();
492- if (PyExceptionInstance_Check (value.ptr ())) {
493- _Py_Identifier PyId_code;
494- PyId_code.string = " code" ;
495- #if PY_VERSION_HEX < 0x030a0000
496- PyId_code.object = 0 ;
497- PyId_code.next = 0 ;
498- #endif
499- PyObject* code = _PyObject_GetAttrId (value.ptr (), &PyId_code);
500- if (code)
491+ if (PyExceptionInstance_Check (value.ptr ())) {
492+ py::object code = py::reinterpret_borrow<py::object>(value.ptr ()).attr (" code" );
493+ if (code) {
501494 value = py::reinterpret_borrow<py::object>(code);
495+ }
502496 }
503- if (!value || value.is_none ())
497+ if (!value || value.is_none ()) {
504498 throw ExitRequest{};
505- else if (PyLong_Check (value.ptr ()))
499+ }
500+ else if (PyLong_Check (value.ptr ())) {
506501 throw ExitRequest{ static_cast <int >(PyLong_AsLong (value.ptr ())) };
507- else
502+ }
503+ else {
508504 throw ExitRequest{ str (value) };
505+ }
509506 }
510507 else {
511508 err.restore ();
You can’t perform that action at this time.
0 commit comments