奇怪的异常行为

2024-09-27 17:34:11 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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


Tags: 程序mostfoobarcallusersfilelast
1条回答
网友
1楼 · 发布于 2024-09-27 17:34:11

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.

相关问题 更多 >

    热门问题