奇怪的异常行为

Strange exception behaviour

我想实现一个异常显示器,但它不起作用,但我有一些不同的东西:

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!

当我指定 IOError 时如何引发 OSError?

IOError只是Python3中OSError的别名,见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.