bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)

diff --git a/Modules/_struct.c b/Modules/_struct.c
index 5954c13..90839b2 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -2088,12 +2088,15 @@
             return 0;
     }
 
-    s_object = PyDict_GetItem(cache, fmt);
+    s_object = PyDict_GetItemWithError(cache, fmt);
     if (s_object != NULL) {
         Py_INCREF(s_object);
         *ptr = (PyStructObject *)s_object;
         return Py_CLEANUP_SUPPORTED;
     }
+    else if (PyErr_Occurred()) {
+        return 0;
+    }
 
     s_object = PyObject_CallFunctionObjArgs((PyObject *)(&PyStructType), fmt, NULL);
     if (s_object != NULL) {