예외가 속성을 가지고있는 것처럼, print
명령 작업입니다. 예외 속성을 탐색 할 수 있습니다. 다음 예제를 고려하십시오.
>>> try:
import some_junk_that_doesnt_exist
except Exception as error:
print(dir(error))
['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__suppress_context__', '__traceback__', '_not_found', 'args', 'msg', 'name', 'path', 'with_traceback']
즉, 목록의 각 예외에 대해 예외의 속성에 액세스 할 수 있습니다. 따라서, 다음을 수행 할 수 있습니다
except Exception as e:
errors.append(e)
:
나에게 발생
for e in err:
print(e.args)
print(e.name)
print(e.msg)
한 가지,하지만, 다음 줄은 정말 오류 목록에 하나 개 이상의 예외를 추가하지해야한다는 것입니다 다른 사람이 내가 아는 것보다 잘 알지만 예외는 아닙니다. 항상 (여기서는 여러 개의 특정 예외를 캡처하지 않는 한) 한 가지가 될 것입니까? 당신이 필요로하는
이것은 정확히 내가 찾고있는 것 같습니다! – OdraEncoded