[Python] Exception 처리 시, 에러 코드 파일 위치 확인 하는 방법

2023. 5. 22. 20:05개발로그/기타

반응형

 

python에서 Exception 처리를 위해 try, except 구문을 넣으면, 에러는 캐치 하는데 에러가 발생한 위치를 알려 주지 않는다.

때문에 디버깅에 어려움을 느낄 수 있다.

 

try, except 구문 사용 시, traceback 모듈을 사용하면 에러가 발생한 코드 위치를 알 수 있다.

 

 

   import traceback
      
   try:
       status, nextTestName = self.runTestSchedule(testSchedule=testSchedule)
   except Exception as ex:
       self.targetIdxLogger.error(traceback.format_exc())

 

반응형