4
파이썬에서 커스텀 트레이스 백을 생성 할 수 있습니까? 파이썬 3의 raise ... from ...
을 모방 한 함수 raise_from()
을 작성하려고합니다.수동으로 파이썬 트레이스 백 생성
def raise_from(exc, cause):
""" Raises the Exception *exc* from the calling stack-frame,
settings its ``__cause__`` to *cause*. """
exc.__cause__ = cause
try: raise Exception
except Exception:
tb = sys.exc_info()[2]
# Remove the last traceback entry.
prelast_tb = tb
while prelast_tb.tb_next:
prelast_tb = prelast_tb.tb_next
prelast_tb.tb_next = None
raise type(exc), exc, tb
불행히도 traceback
인스턴스의 속성은 읽기 전용입니다.
추적 표시를 출력하고 싶지 않습니다. 특정 추적을 사용하여 예외를 발생시키고 싶습니다. 그 예외는 여전히 붙잡혀 인쇄되지 않을 수 있습니다. –