Skip to content

Commit

Permalink
change to more specific exception
Browse files Browse the repository at this point in the history
  • Loading branch information
moosetraveller committed Sep 1, 2023
1 parent efefef9 commit abbd3df
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/aputil/xcursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

from typing import List, Dict, Union, Generator
from collections.abc import Generator
from typing import List, Dict, Union

import arcpy
import arcpy, arcpy.da

__all__ = ["xcursor", "XRow"]

Expand All @@ -64,7 +65,7 @@ def get(self, field_name: str, default_value: any = None):
return a default value when the field's value is None.
"""
if field_name is None or field_name.upper() not in self._fields:
raise Exception("Field {} does not exist.".format(field_name))
raise KeyError("Field {} does not exist.".format(field_name))
value = self.row[self._fields[field_name.upper()]]
if not value:
return default_value
Expand All @@ -77,7 +78,7 @@ def get_by_index(self, index: int, default_value: any = None):
return a default value when the field's value is None.
"""
if index >= len(self.row):
raise Exception("Index {} is out of range.".format(index))
raise IndexError("Index {} is out of range.".format(index))
value = self.row[index]
if not value:
return default_value
Expand All @@ -95,7 +96,7 @@ def to_row(self, update_values: Dict[str, any] = None) -> List[any]:
in zip(self.fields, self.row)
]

def xcursor(cursor: arcpy.da.SearchCursor, cursor_name=None) -> Generator[XRow, None, None]:
def xcursor(cursor: arcpy.da.SearchCursor) -> Generator[XRow, None, None]:
"""
Generator wrapping an arcpy cursor providing XRow instances. A XRow instance provides
Expand Down

0 comments on commit abbd3df

Please sign in to comment.