Skip to content

Correctly catch errors #2

@saralk

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.

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