A developer writes a function that reads a configuration file and returns its contents as a string. The file might not exist. Which exception should be caught to handle a missing file?
Trap 1: PermissionError
PermissionError is for access issues, not missing file.
Trap 2: IOError
IOError is an alias for OSError, not specific to missing file.
Trap 3: OSError
OSError is too broad; it includes other I/O errors.
- A
FileNotFoundError
FileNotFoundError is specifically for missing files.
- B
PermissionError
Why wrong: PermissionError is for access issues, not missing file.
- C
IOError
Why wrong: IOError is an alias for OSError, not specific to missing file.
- D
OSError
Why wrong: OSError is too broad; it includes other I/O errors.