Browse Source

fix exception handling in Python 2

rdb 13 years ago
parent
commit
151b22ddf0
1 changed files with 8 additions and 4 deletions
  1. 8 4
      makepanda/makepandacore.py

+ 8 - 4
makepanda/makepandacore.py

@@ -903,7 +903,8 @@ def ReadFile(wfile):
         data = srchandle.read()
         data = srchandle.read()
         srchandle.close()
         srchandle.close()
         return data
         return data
-    except ex:
+    except:
+        ex = sys.exc_info()[1]
         exit("Cannot read %s: %s" % (wfile, ex))
         exit("Cannot read %s: %s" % (wfile, ex))
 
 
 def ReadBinaryFile(wfile):
 def ReadBinaryFile(wfile):
@@ -912,7 +913,8 @@ def ReadBinaryFile(wfile):
         data = srchandle.read()
         data = srchandle.read()
         srchandle.close()
         srchandle.close()
         return data
         return data
-    except ex:
+    except:
+        ex = sys.exc_info()[1]
         exit("Cannot read %s: %s" % (wfile, ex))
         exit("Cannot read %s: %s" % (wfile, ex))
 
 
 def WriteFile(wfile, data):
 def WriteFile(wfile, data):
@@ -920,7 +922,8 @@ def WriteFile(wfile, data):
         dsthandle = open(wfile, "w")
         dsthandle = open(wfile, "w")
         dsthandle.write(data)
         dsthandle.write(data)
         dsthandle.close()
         dsthandle.close()
-    except ex:
+    except:
+        ex = sys.exc_info()[1]
         exit("Cannot write to %s: %s" % (wfile, ex))
         exit("Cannot write to %s: %s" % (wfile, ex))
 
 
 def WriteBinaryFile(wfile, data):
 def WriteBinaryFile(wfile, data):
@@ -928,7 +931,8 @@ def WriteBinaryFile(wfile, data):
         dsthandle = open(wfile, "wb")
         dsthandle = open(wfile, "wb")
         dsthandle.write(data)
         dsthandle.write(data)
         dsthandle.close()
         dsthandle.close()
-    except ex:
+    except:
+        ex = sys.exc_info()[1]
         exit("Cannot write to %s: %s" % (wfile, ex))
         exit("Cannot write to %s: %s" % (wfile, ex))
 
 
 def ConditionalWriteFile(dest, desiredcontents):
 def ConditionalWriteFile(dest, desiredcontents):