Skip to content

Commit

Permalink
added a try and catch block
Browse files Browse the repository at this point in the history
  • Loading branch information
sridhar-mani committed Nov 20, 2024
1 parent e0895c0 commit 24b1952
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
]
}
8 changes: 6 additions & 2 deletions fipy/meshes/nonUniformGrid1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ def __init__(self, dx=1., nx=None, overlap=2,
_RepresentationClass=_Grid1DRepresentation,
_TopologyClass=_Grid1DTopology):

if not isinstance(nx, int) or nx < 0:
raise ValueError("nx must be a non-negative integer")
try:
if not isinstance(nx, int) or nx < 0:
raise ValueError("nx must be a non-negative integer")
except ValueError as e:
print(f"Error: {e}")
raise

builder = _BuilderClass()

Expand Down
8 changes: 6 additions & 2 deletions fipy/meshes/nonUniformGrid2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ class NonUniformGrid2D(Mesh2D):
"""
def __init__(self, dx=1., dy=1., nx=None, ny=None, overlap=2, communicator=parallelComm,
_RepresentationClass=_Grid2DRepresentation, _TopologyClass=_Grid2DTopology):
if (not isinstance(nx, int) or nx < 0) and (not isinstance(ny, int) or ny < 0):
raise ValueError("nx must be a non-negative integer")
try:
if (not isinstance(nx, int) or nx < 0) and (not isinstance(ny, int) or ny < 0):
raise ValueError("nx must be a non-negative integer")
except ValueError as e:
print(f"Error: {e}")
raise

builder = _NonuniformGrid2DBuilder()

Expand Down
10 changes: 7 additions & 3 deletions fipy/meshes/nonUniformGrid3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ class NonUniformGrid3D(Mesh):
"""
def __init__(self, dx = 1., dy = 1., dz = 1., nx = None, ny = None, nz = None, overlap=2, communicator=parallelComm,
_RepresentationClass=_Grid3DRepresentation, _TopologyClass=_Grid3DTopology):

if (not isinstance(nx, int) or nx < 0) and (not isinstance(ny, int) or ny < 0) and (not isinstance(nz, int) or nz < 0):
raise ValueError("nx must be a non-negative integer")

try:
if (not isinstance(nx, int) or nx < 0) and (not isinstance(ny, int) or ny < 0) and (not isinstance(nz, int) or nz < 0):
raise ValueError("nx must be a non-negative integer")
except ValueError as e:
print(f"Error: {e}")
raise

builder = _NonuniformGrid3DBuilder()

Expand Down

0 comments on commit 24b1952

Please sign in to comment.