Skip to content

Commit

Permalink
replace if..else with try..except in bridge.py (#903)
Browse files Browse the repository at this point in the history
* replace if..else with try..except

* add AttributeError exception

* Update bridge.py
  • Loading branch information
rieder committed Nov 19, 2022
1 parent 9090380 commit 616fec2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/amuse/couple/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
from amuse.units import quantities
from amuse.units import units, constants, generic_unit_system, nbody_system
from amuse import datamodel
from amuse.support.exceptions import AmuseException
from amuse.support.exceptions import AmuseException, CoreException



Expand Down Expand Up @@ -320,12 +320,13 @@ def __init__(self, code, field_codes, do_sync=True, verbose=False, radius_is_eps
required_attributes.append('h_smooth')
self.required_attributes = lambda p, x : x in required_attributes

if not hasattr(self.code,"parameters"):
self.zero_smoothing=True
elif not hasattr(self.code.parameters,"epsilon_squared"):
self.zero_smoothing=True
else:
self.zero_smoothing=zero_smoothing
try:
hasattr(self.code.parameters, "epsilon_squared")
self.zero_smoothing = zero_smoothing
except AttributeError:
self.zero_smoothing = True
except CoreException: # hasattr will fail with an exception
self.zero_smoothing = True


def evolve_model(self,tend,timestep=None):
Expand Down

0 comments on commit 616fec2

Please sign in to comment.