Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove any usage of bare exception. #4331

Merged
merged 20 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _unittest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
try:
with open(local_config_file) as f:
local_config = json.load(f)
except: # pragma: no cover
except Exception: # pragma: no cover
local_config = {}
config.update(local_config)

Expand Down
6 changes: 3 additions & 3 deletions _unittest/test_01_Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_34_force_project_path_disable(self):
h = Hfss("c:/dummy/test.aedt", specified_version=desktop_version)
except Exception as e:
exception_raised = True
assert e.args[0] == "Project doesn't exists. Check it and retry."
assert e.args[0] == "Project doesn't exist. Check it and retry."
assert exception_raised
settings.force_error_on_missing_project = False

Expand Down Expand Up @@ -374,15 +374,15 @@ def test_36_test_load(self, add_app):
f.write(" ")
try:
hfss = Hfss(projectname=file_name2, specified_version=desktop_version)
except:
except Exception as e:
MaxJPRey marked this conversation as resolved.
Show resolved Hide resolved
assert True
try:
os.makedirs(os.path.join(self.local_scratch.path, "test_36_2.aedb"))
file_name3 = os.path.join(self.local_scratch.path, "test_36_2.aedb", "edb.def")
with open(file_name3, "w") as f:
f.write(" ")
hfss = Hfss3dLayout(projectname=file_name3, specified_version=desktop_version)
except:
except Exception as e:
MaxJPRey marked this conversation as resolved.
Show resolved Hide resolved
assert True

def test_37_add_custom_toolkit(self, desktop):
Expand Down
2 changes: 1 addition & 1 deletion _unittest/test_02_3D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def test_35_activate_variable_for_tuning(self):
try:
self.aedtapp.activate_variable_tuning("Idontexist")
assert False
except:
except Exception:
assert True

def test_36_activate_variable_for_optimization(self):
Expand Down
2 changes: 1 addition & 1 deletion _unittest/test_12_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def test_71_antenna_plot(self, field_test):
try:
p = ffdata.polar_plot_3d_pyvista(farfield_quantity="RealizedGain", convert_to_db=True, show=False)
assert isinstance(p, object)
except:
except Exception:
assert True

@pytest.mark.skipif(is_linux or sys.version_info < (3, 8), reason="FarFieldSolution not supported by IronPython")
Expand Down
2 changes: 1 addition & 1 deletion _unittest/test_21_Circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def test_34_activate_variables(self):
try:
self.aedtapp.activate_variable_tuning("Idontexist")
assert False
except:
except Exception:
assert True

def test_35_netlist_data_block(self):
Expand Down
2 changes: 1 addition & 1 deletion _unittest_solvers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
try:
with open(local_config_file) as f:
local_config = json.load(f)
except: # pragma: no cover
except Exception: # pragma: no cover
local_config = {}
config.update(local_config)

Expand Down
8 changes: 4 additions & 4 deletions _unittest_solvers/test_26_emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ def test_04_radio_component(self, add_app):
exception_raised = False
try:
radio.set_band_power_level(100)
except:
except Exception:
exception_raised = True
assert exception_raised
# Try getting band power from the radio
exception_raised = False
try:
radio.get_band_power_level()
except:
except Exception:
exception_raised = True
assert exception_raised
# full units support added with 2023.2
Expand Down Expand Up @@ -561,7 +561,7 @@ def test_10_radio_band_getters(self, add_app):
exception_raised = False
try:
freqs = rev.get_active_frequencies(radios[0], bands[0], TxRxMode.BOTH, "MHz")
except:
except Exception:
exception_raised = True
assert exception_raised

Expand Down Expand Up @@ -628,7 +628,7 @@ def test_11_sampling_getters(self, add_app):
exception_raised = False
try:
rad.set_channel_sampling()
except:
except Exception:
exception_raised = True
assert exception_raised

Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def run(self):
def autodoc_skip_member(app, what, name, obj, skip, options):
try:
exclude = True if ".. deprecated::" in obj.__doc__ else False
except:
except Exception:
exclude = False
exclude2 = True if name.startswith("_") else False
return True if (skip or exclude or exclude2) else None # Can interfere with subsequent skip functions.
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def custom_show_warning(message, category, filename, lineno, file=None, line=Non

try:
from pyaedt.generic.design_types import Hfss3dLayout
except:
except Exception:
from pyaedt.generic.design_types import Hfss3dLayout

from pyaedt.generic.design_types import Circuit
Expand Down
6 changes: 3 additions & 3 deletions pyaedt/aedt_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _log_on_desktop(self):
return True
else:
return False
except: # pragma: no cover
except Exception: # pragma: no cover
return False

@_log_on_desktop.setter
Expand Down Expand Up @@ -590,7 +590,7 @@ def _log_on_dekstop(self, message_type, message_text, level=None, proj_name=None
des_name = des_name[des_name.find(";") + 1 :]
try:
self._desktop.AddMessage(proj_name, des_name, message_type, message_text)
except:
except Exception:
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved
print("PyAEDT INFO: Failed in Adding Desktop Message")

def _log_on_handler(self, message_type, message_text, *args, **kwargs):
Expand Down Expand Up @@ -658,7 +658,7 @@ def clear_messages(self, proj_name=None, des_name=None, level=2):
des_name = self.design_name
try:
self._desktop.ClearMessages(proj_name, des_name, level)
except:
except Exception:
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved
pass

@property
Expand Down
38 changes: 19 additions & 19 deletions pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def existing_analysis_sweeps(self):
elif self.solution_type not in ["Eigenmode"]:
try:
sweeps = list(self.oanalysis.GetSweeps(el))
except:
except Exception:
sweeps = []
for sw in sweeps:
if el + " : " + sw not in sweep_list:
Expand Down Expand Up @@ -431,7 +431,7 @@ def excitations(self):
del list_names[1::2]
list_names = list(set(list_names))
return list_names
except:
except Exception:
return []

@pyaedt_function_handler()
Expand Down Expand Up @@ -545,12 +545,12 @@ def list_of_variations(self, setup_name=None, sweep_name=None):
):
try:
return list(self.osolution.ListVariations("{0} : {1}".format(setup_name, sweep_name)))
except:
except Exception:
return [""]
else:
try:
return list(self.odesign.ListVariations("{0} : {1}".format(setup_name, sweep_name)))
except:
except Exception:
return [""]

@pyaedt_function_handler()
Expand Down Expand Up @@ -646,7 +646,7 @@ def export_results(
try:
self.post.oreportsetup.ExportToFile(str(report_name), export_path)
self.logger.info("Export Data: {}".format(export_path))
except:
except Exception:
pass
exported_files.append(export_path)

Expand Down Expand Up @@ -757,7 +757,7 @@ def export_results(
)
exported_files.append(export_path)
self.logger.info("Exported Touchstone: %s", export_path)
except:
except Exception:
self.logger.warning("Export SnP failed: no solutions found")
elif self.design_type == "2D Extractor":
export_path = os.path.join(
Expand All @@ -779,7 +779,7 @@ def export_results(
)
exported_files.append(export_path)
self.logger.info("Exported Touchstone: %s", export_path)
except:
except Exception:
self.logger.warning("Export SnP failed: no solutions found")
elif self.design_type == "Q3D Extractor":
export_path = os.path.join(
Expand All @@ -800,7 +800,7 @@ def export_results(
)
exported_files.append(export_path)
self.logger.info("Exported Touchstone: %s", export_path)
except:
except Exception:
self.logger.warning("Export SnP failed: no solutions found")
else:
self.logger.warning("Setup is not solved. To export results please analyze setup first.")
Expand Down Expand Up @@ -895,9 +895,9 @@ def _get_native_data(self):
ds,
)
)
except:
except Exception:
pass
except:
except Exception:
pass
return boundaries

Expand Down Expand Up @@ -1709,7 +1709,7 @@ def analyze_setup(
try:
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, name)
set_custom_dso = True
except:
except Exception:
pass
elif num_gpu or num_tasks or num_cores:
config_name = "pyaedt_config"
Expand All @@ -1734,7 +1734,7 @@ def analyze_setup(
self.logger.error("Permission denied.")
skip_files = True
# For other errors
except:
except Exception:
self.logger.error("Error occurred while copying file.")
skip_files = True
if not skip_files:
Expand Down Expand Up @@ -1783,7 +1783,7 @@ def analyze_setup(
self._desktop.SetRegistryFromFile(target_name)
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, config_name)
set_custom_dso = True
except:
except Exception:
pass
if not name:
try:
Expand All @@ -1792,7 +1792,7 @@ def analyze_setup(
self.odesign.AnalyzeAll(blocking)
else:
self.odesign.AnalyzeAll()
except:
except Exception:
if set_custom_dso:
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, active_config)
self.logger.error("Error in solving all setups (AnalyzeAll).")
Expand All @@ -1806,7 +1806,7 @@ def analyze_setup(
self.odesign.Analyze(name, blocking)
else:
self.odesign.Analyze(name)
except:
except Exception:
if set_custom_dso:
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, active_config)
self.logger.error("Error in Solving Setup %s", name)
Expand All @@ -1815,7 +1815,7 @@ def analyze_setup(
try:
self.logger.info("Solving Optimetrics")
self.ooptimetrics.SolveSetup(name)
except:
except Exception:
if set_custom_dso:
self.set_registry_key(r"Desktop/ActiveDSOConfigurations/" + self.design_type, active_config)
self.logger.error("Error in Solving or Missing Setup %s", name)
Expand Down Expand Up @@ -2228,7 +2228,7 @@ def value_with_units(
else:
try:
units = self.odesktop.GetDefaultUnit(unit_system)
except:
except Exception:
self.logger.warning("Defined unit system is incorrect.")
units = ""
from pyaedt.generic.general_methods import _dim_arg
Expand Down Expand Up @@ -2331,13 +2331,13 @@ def export_rl_matrix(
precision,
is_exponential,
)
except:
except Exception:
self.logger.error("Solutions are empty. Solve before exporting.")
return False
else:
try:
self.oanalysis.ExportSolnData(analysis_setup, matrix_name, is_post_processed, variations, file_path)
except:
except Exception:
self.logger.error("Solutions are empty. Solve before exporting.")
return False

Expand Down
4 changes: 2 additions & 2 deletions pyaedt/application/AnalysisNexxim.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def push_down(self, component_name):
try:
self.oproject.SetActiveDesign(out_name)
self.__init__(projectname=self.project_name, designname=out_name)
except: # pragma: no cover
except Exception: # pragma: no cover
return False
return True

Expand All @@ -141,7 +141,7 @@ def pop_up(self):
parent_name = self.odesign.GetName().split(";")[1].split("/")[0]
self.oproject.SetActiveDesign(parent_name)
self.__init__(projectname=self.project_name, designname=parent_name)
except:
except Exception:
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion pyaedt/application/AnalysisRMxprt.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def set_material_threshold(self, conductivity=100000, permeability=100):
try:
self.odesign.SetThreshold(conductivity, permeability)
return True
except:
except Exception:
return False

@pyaedt_function_handler()
Expand Down
Loading
Loading