📜  python手动触发异常——Python代码示例

📅  最后修改于: 2022-03-11 14:46:30.589000             🧑  作者: Mango

代码示例1
def demo_bad_catch():
    try:
        raise ValueError('Represents a hidden bug, do not catch this')
        raise Exception('This is the exception you expect to handle')
    except Exception as error:
        print('Caught this error: ' + repr(error))

>>> demo_bad_catch()
Caught this error: ValueError('Represents a hidden bug, do not catch this',)