FEM: python, get rid of bare excepts

This commit is contained in:
Bernd Hahnebach
2020-10-27 08:23:12 +01:00
parent 70e11ebc52
commit 6fda0a2faa
10 changed files with 16 additions and 9 deletions

View File

@@ -34,6 +34,13 @@ These coding rules apply to FEM module code only. Other modules or the base syst
- maximal line length is 100
- double quotes as string identifier
### Exceptione
- Do not use bare 'except'.
- Be more specific. If not possible use:
- Either use 'except Exception' or if really everything should be catched 'except BaseException'
- https://stackoverflow.com/a/18982772
- https://github.com/PyCQA/pycodestyle/issues/703
### Imports
- Only one import per line.
- Even on import from some_module import something. There should only be one something per line.

View File

@@ -101,7 +101,7 @@ def readResult(
m["frequency"] = mode_frequency
results.append(m)
mode_reading = True
except:
except Exception:
if mode_reading:
# Conversion error after mode reading started, so it's the end of section
eigenvalue_output_section_found = False

View File

@@ -214,7 +214,7 @@ def read_inp(file_name):
try:
enode = int(line_list[en])
elm_category[number].append(enode)
except:
except Exception:
elm_2nd_line = True
break

View File

@@ -831,7 +831,7 @@ class GmshTools():
# but the warnings are in stderr and thus printed :-)
# print(output)
# print(error)
except:
except Exception:
error = "Error executing: {}\n".format(" ".join(comandlist))
Console.PrintError(error)
self.error = True

View File

@@ -116,7 +116,7 @@ class Task(object):
def protector(self):
try:
self.run()
except:
except Exception:
self.fail()
raise

View File

@@ -201,7 +201,7 @@ class _TaskPanel:
error = ""
try:
error = gmsh_mesh.create_mesh()
except:
except Exception:
import sys
FreeCAD.Console.PrintMessage(
"Unexpected error when creating mesh: {}\n"

View File

@@ -235,7 +235,7 @@ class _TaskPanel:
# self.result_widget.hsb_displacement_factor.setValue(df)
self.result_widget.sb_displacement_factor_max.setValue(dfm)
self.result_widget.sb_displacement_factor.setValue(df)
except:
except Exception:
self.restore_initial_result_dialog()
def restore_initial_result_dialog(self):

View File

@@ -285,7 +285,7 @@ class _TaskPanel:
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
self.fea.load_results()
except:
except Exception:
FreeCAD.Console.PrintError("loading results failed\n")
QApplication.restoreOverrideCursor()

View File

@@ -377,7 +377,7 @@ class FemToolsCcx(QtCore.QRunnable, QtCore.QObject):
self.working_dir
)
self.inp_file_name = inp_writer.write_calculix_input_file()
except:
except Exception:
FreeCAD.Console.PrintError(
"Unexpected error when writing CalculiX input file: {}\n"
.format(sys.exc_info()[0])

View File

@@ -249,7 +249,7 @@ def getBoundBoxOfAllDocumentShapes(doc):
if hasattr(o, "Shape") and hasattr(o.Shape, "BoundBox"):
try:
bb = o.Shape.BoundBox
except:
except Exception:
bb = None
if bb.isValid():
if not overalboundbox: