Search code examples
pythonexceptionioerrorpython-3.5

Strange exception behaviour


I want to implement an exception displayer and it doesn't work, but I have something different:

Traceback (most recent call last):
    File "/Users/honzik/PycharmProjects/Toy/test.py", line 21, in main
    raise IOError('Foo bar bazooka!')
OSError: Foo bar bazooka!

How can be raised an OSError when I specified IOError?


Solution

  • IOError is only an alias for OSError in Python3, see https://docs.python.org/3/library/exceptions.html#concrete-exceptions:

    Changed in version 3.3: EnvironmentError, IOError, WindowsError, VMSError, socket.error, select.error and mmap.error have been merged into OSError, and the constructor may return a subclass.