Raising exceptions when an exception is already present in Python 3

前端 未结 5 1683
感情败类
感情败类 2020-12-14 05:52

What happens to my first exception (A) when the second (B) is raised in the following code?

class A(Exception): pass
class B(Except         


        
5条回答
  •  醉酒成梦
    2020-12-14 06:27

    Answering to question 3, you can use:

    raise B('second') from None
    

    Which will remove the exception A traceback.

    Traceback (most recent call last):
      File "raising_more_exceptions.py", line 8, in 
        raise B('second')
    __main__.B: second
    

提交回复
热议问题