[OTHER] Catch only Exception, not BaseException

This commit is contained in:
Chris Hennes
2021-02-10 14:09:11 -06:00
committed by wwmayer
parent a7522c384e
commit 6b16e12d7c
18 changed files with 38 additions and 38 deletions

View File

@@ -272,12 +272,12 @@ def decodeName(name,scale,thickness):
if len(name) > 1:
try:
scale = float(name[1])
except:
except Exception:
pass
if len(name) > 2:
try:
thickness = float(name[2])
except:
except Exception:
pass
return name[0],scale,thickness

View File

@@ -155,7 +155,7 @@ def cmdCreateImageScaling(name, trackers):
ok = True
elif q.Unit == FreeCAD.Units.Length:
ok = True
except:
except Exception:
ok = False
if not ok:
raise ValueError

View File

@@ -658,11 +658,11 @@ def VALUE(V):
# first try to instantiate an INTEGER from the string:
try:
return INTEGER(V)
except:
except Exception:
pass #not possible, try to cast to REAL
try:
return REAL(V)
except:
except Exception:
pass
# else return None
return None

View File

@@ -9,7 +9,7 @@ import time, tempfile, math
# http://python-kurs.eu/threads.php
try:
import _thread as thread
except:
except Exception:
import thread

View File

@@ -106,7 +106,7 @@ def colorcodeshapes(objs):
st = mostbasiccompound(obj.Shape)
color=shapecolors[st]
obj.ViewObject.ShapeColor = color
except:
except Exception:
raise
#colorcodeshapes(App.ActiveDocument.Objects)

View File

@@ -944,7 +944,7 @@ def p_cylinder_action(p):
try :
import Draft
mycyl.Base = Draft.makePolygon(n,r1,face=True)
except :
except Exception:
# If Draft can't import (probably due to lack of Pivy on Mac and
# Linux builds of FreeCAD), this is a fallback.
# or old level of FreeCAD
@@ -1182,7 +1182,7 @@ def p_polyhedron_action(p) :
print(w)
try:
f = Part.Face(w)
except:
except Exception:
secWireList = w.Edges[:]
f = Part.makeFilledFace(Part.__sortEdges__(secWireList))
#f = make_face(v[int(i[0])],v[int(i[1])],v[int(i[2])])

View File

@@ -640,10 +640,10 @@ void TaskCheckGeometryResults::buildShapeContent(const QString &baseName, const
cmdstream << "if hasattr(_shp,'normalAt'):" << std::endl;
cmdstream << " try:" << std::endl;
cmdstream << " _result += 'normalAt(0): '+str([round(vv," << decimals << ") for vv in _shp.normalAt(0)]) +'\\n'" << std::endl;
cmdstream << " except:" << std::endl;
cmdstream << " except Exception:" << std::endl;
cmdstream << " try:" << std::endl;
cmdstream << " _result += 'normalAt(0,0): '+str([round(vv," << decimals << ") for vv in _shp.normalAt(0,0)]) +'\\n'" << std::endl;
cmdstream << " except:" << std::endl;
cmdstream << " except Exception:" << std::endl;
cmdstream << " pass" << std::endl;
cmdstream << "if hasattr(_shp, 'isClosed') and ('Wire' in _type or 'Edge' in _type):" << std::endl;
cmdstream << " _result += 'isClosed: '+str(_shp.isClosed())+'\\n'" << std::endl;

View File

@@ -47,7 +47,7 @@ class PartDesignWorkbench ( Workbench ):
print("Wizard shaft module cannot be loaded")
try:
from FeatureHole import HoleGui
except:
except Exception:
pass
import PartDesignGui

View File

@@ -11,7 +11,7 @@ Gui=FreeCADGui
def proceed():
try:
compute()
except:
except Exception:
hide()
QtGui.QApplication.restoreOverrideCursor()

View File

@@ -346,7 +346,7 @@ class TaskPanel(object):
name, info = self.addCustomProperty(self.obj, dialog)
try:
setattr(obj, nam, val)
except:
except Exception:
# this can happen if the old enumeration value doesn't exist anymore
pass
newVal = PathUtil.getPropertyValueString(obj, nam)

View File

@@ -186,7 +186,7 @@ def isValidFileName(filename):
try:
with open(filename, "w") as tempfile:
return True
except:
except Exception:
return False

View File

@@ -768,7 +768,7 @@ class SpreadsheetCases(unittest.TestCase):
try:
sheet.setAlias("A2","Test")
self.fail("An ambiguous alias was set which shouldn't be allowed")
except:
except Exception:
self.assertEqual(sheet.getAlias("A2"),None)
def testClearAlias(self):
@@ -783,7 +783,7 @@ class SpreadsheetCases(unittest.TestCase):
sheet = self.doc.addObject("Spreadsheet::Sheet","Calc")
try:
sheet.setAlias("A1","B1")
except:
except Exception:
self.assertEqual(sheet.getAlias("A1"),None)
else:
self.fail("A cell address was used as alias which shouldn't be allowed")
@@ -793,7 +793,7 @@ class SpreadsheetCases(unittest.TestCase):
sheet = self.doc.addObject("Spreadsheet::Sheet","Calc")
try:
sheet.setAlias("A1","mA")
except:
except Exception:
self.assertEqual(sheet.getAlias("A1"), None)
else:
self.fail("A unit (reserved word) was used as alias which shouldn't be allowed")

View File

@@ -37,7 +37,7 @@ class ConsoleTestCase(unittest.TestCase):
# http://python-kurs.eu/threads.php
try:
import _thread as thread, time
except:
except Exception:
import thread, time
def adder():
lock.acquire()
@@ -58,7 +58,7 @@ class ConsoleTestCase(unittest.TestCase):
# http://python-kurs.eu/threads.php
try:
import _thread as thread, time
except:
except Exception:
import thread, time
def adder():
self.count=self.count+1

View File

@@ -122,7 +122,7 @@ class DocumentBasicCases(unittest.TestCase):
# test read only mechanismus
try:
self.Doc.UndoCount = 3
except:
except Exception:
FreeCAD.Console.PrintLog(" exception thrown, OK\n")
else:
self.fail("no exception thrown")
@@ -167,7 +167,7 @@ class DocumentBasicCases(unittest.TestCase):
self.failUnless(L1.Enum == "Two", "Different value to 'Two'")
try:
L1.Enum = "SurelyNotInThere!"
except:
except Exception:
FreeCAD.Console.PrintLog(" exception thrown, OK\n")
else:
self.fail("no exception thrown")
@@ -218,7 +218,7 @@ class DocumentBasicCases(unittest.TestCase):
self.Doc.removeObject(L1.Name)
try:
L1.Name
except:
except Exception:
self.failUnless(True)
else:
self.failUnless(False)
@@ -232,7 +232,7 @@ class DocumentBasicCases(unittest.TestCase):
self.Doc.undo()
try:
L2.Name
except:
except Exception:
self.failUnless(True)
else:
self.failUnless(False)
@@ -251,7 +251,7 @@ class DocumentBasicCases(unittest.TestCase):
grp.addObject(obj)
self.failUnless(len(grp.Group) == 1)
self.failUnless(grp.Group[0] == obj)
except:
except Exception:
self.failUnless(False)
#test if the method override works
@@ -268,7 +268,7 @@ class DocumentBasicCases(unittest.TestCase):
self.failUnless(grp2.hasExtension("App::GroupExtension"))
grp2.addObject(obj)
self.failUnless(len(grp2.Group) == 0)
except:
except Exception:
self.failUnless(True)
self.Doc.removeObject(grp.Name)
@@ -456,7 +456,7 @@ class DocumentSaveRestoreCases(unittest.TestCase):
Active = FreeCAD.activeDocument()
# Second is still a valid object
self.failUnless(Second != Active)
except:
except Exception:
# Okay, no document open
self.failUnless(True)
@@ -925,7 +925,7 @@ class DocumentGroupCases(unittest.TestCase):
# Adding the group to itself must fail
try:
G1.addObject(G1)
except:
except Exception:
FreeCAD.Console.PrintLog("Cannot add group to itself, OK\n")
else:
self.fail("Adding the group to itself must not be possible")
@@ -1027,7 +1027,7 @@ class DocumentGroupCases(unittest.TestCase):
grp = prt1.Group
grp.append(obj1)
prt1.Group = grp
except:
except Exception:
grp.remove(obj1)
self.failUnless(prt1.Group == grp)
else:
@@ -1039,7 +1039,7 @@ class DocumentGroupCases(unittest.TestCase):
grp.append(obj1)
try:
grp1.Group = grp
except:
except Exception:
pass
else:
self.fail("No exception thrown when object is in multiple Groups")
@@ -1080,7 +1080,7 @@ class DocumentGroupCases(unittest.TestCase):
prt2.Group = []
try:
prt2.Group = [prt2]
except:
except Exception:
pass
else:
self.fail("Exception is expected")
@@ -1167,7 +1167,7 @@ class DocumentPlatformCases(unittest.TestCase):
self.Doc = FreeCAD.open(self.DocName)
self.failUnless(self.Doc.Points.Points.count() == 0)
except:
except Exception:
pass
def tearDown(self):

View File

@@ -77,7 +77,7 @@ class BaseGUITestRunner:
self.__rollbackImporter = RollbackImporter()
try:
test = unittest.defaultTestLoader.loadTestsFromName(testName)
except:
except Exception:
exc_type, exc_value, exc_tb = sys.exc_info()
#apply(traceback.print_exception,sys.exc_info())
traceback.print_exception(*sys.exc_info())

View File

@@ -73,7 +73,7 @@ class BaseGUITestRunner:
self.__rollbackImporter = RollbackImporter()
try:
test = unittest.defaultTestLoader.loadTestsFromName(testName)
except:
except Exception:
exc_type, exc_value, exc_tb = sys.exc_info()
traceback.print_exception(*sys.exc_info())
self.errorDialog("Unable to run test '%s'" % testName,

View File

@@ -37,13 +37,13 @@ def pythonToolbars():
if hasattr(Gui, "draftToolBar"):
try:
Gui.draftToolBar.Activated()
except:
except Exception:
m = "Persistent toolbars: draftToolBar toolbar not managed.\n"
App.Console.PrintMessage(m)
if hasattr(Gui, "Snapper"):
try:
Gui.Snapper.show()
except:
except Exception:
m = "Persistent toolbars: Snapper toolbar not managed.\n"
App.Console.PrintMessage(m)
else: