Created
December 25, 2020 16:57
-
-
Save farisachugthai/e48e4de21cd3c09ba673a1b57c4511da to your computer and use it in GitHub Desktop.
Do IOError and OSError catch each other correctly?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""IOError and OSError are seemingly interchangeable! | |
The reference docs encourage using OSError; however, they seemingly | |
work with each other just fine. | |
""" | |
def raise_ioerr(): | |
raise IOError | |
def raise_oserr(): | |
raise OSError | |
def catch_io(): | |
try: | |
raise_oserr() | |
except IOError: | |
print("IOError catches OSError") | |
def catch_os(): | |
try: | |
raise_ioerr() | |
except OSError: | |
print("OSError catches IOError") | |
def main(): | |
catch_io() | |
catch_os() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment