Skip to content

Instantly share code, notes, and snippets.

@farisachugthai
Created December 25, 2020 16:57
Show Gist options
  • Save farisachugthai/e48e4de21cd3c09ba673a1b57c4511da to your computer and use it in GitHub Desktop.
Save farisachugthai/e48e4de21cd3c09ba673a1b57c4511da to your computer and use it in GitHub Desktop.
Do IOError and OSError catch each other correctly?
"""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