카테고리 없음
[파이썬] 매우 간단한 파이썬 3 시도를 제외하고 ValueError가 트리핑되지 않습니다.
행복을전해요
2021. 2. 24. 18:11
예외를 다시 제기하고 있습니다. 설계된대로 작동합니다.
은 test
바로 역 추적 이전이 상단에 인쇄 된,하지만 당신은 사용 raise
예외가 여전히 역 추적을 일으키는 있도록 :
>>> def main():
... try:
... test = int("hello")
... except ValueError:
... print("test")
... raise
...
>>> main()
test
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in main
ValueError: invalid literal for int() with base 10: 'hello'
제거 raise
하고 바로 test
인쇄 남아 :
>>> def main():
... try:
... test = int("hello")
... except ValueError:
... print("test")
...
>>> main()
test
출처
https://stackoverflow.com/questions/22080086