Skip to content

Correctly catch errors #2

Open
Open

Description

@saralk

try:
with open(path) as inputData:
contents = inputData.read().splitlines()
inputData.close()
return contents
except:
print("File not found!")

This will catch any error, not just FileNotFoundErrors, so you should catch that error specifically.

You could also get away with not catching this error, as if an error is thrown it will stop executing the code.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions