Skip to content

Raising more appropriate exception types #146

Open

Description

@karimbahgat

Right now exceptions are raised either as ShapefileException (dealing specifically with the Shapefile), or just a generic Exception. At some point should go through all the generic exceptions and change them to more appropriate exception types, such as ValueError, TypeError, etc.

Activity

  1. JamesParrott commented on Jun 22, 2026

    @JamesParrott
    Collaborator

    Replacing them with more specific, more informative, subclasses of our ShapefileException would definitely improve both the code base and the UX. I've recently added a class dbfFileException(ShapefileException ).

    But the suggestion as strictly stated: replacing raise ShapefileException with raise ValueError etc. would be a breaking change to our API.

    Users who have enclosed calls to PyShp inside try: ... except ShapefileException:, who upgraded PyShp, would no longer suppress ShapefileExceptions (them having been changed to ValueErrors. etc.)

    Users calling out to PyShp and running other code too, inside try: ... except ValueError: intending to catch some other ValueError, but let ShapefileExceptions be raised, after upgrading PyShp could now unintentionally also suppress the former ShapefileExceptions (this also occurs if we replace the exceptions with new ones that inherit from both ShapefileException and ValueError, but that would be very unusual, I don't remember ever seeing that before).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions