강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

김재민님의 프로필 이미지
김재민

작성한 질문수

프로그래밍 시작하기 : 파이썬 입문 (Inflearn Original)

Exception(1-2)

raise를 이용하여 Error를 발생시킬경우 as를 통해 Error가 발생한 부분을 출력 할 수 없는건가요?

작성

·

338

1

항상 친절한 답변 감사합니다 

답변 1

1

좋은사람님의 프로필 이미지
좋은사람
지식공유자

def demo_bad_catch():
    try:
        raise ValueError('Represents a hidden bug, do not catch this')
        raise Exception('This is the exception you expect to handle')
    except Exception as error:
        print('Caught this error: ' + repr(error))

>>> demo_bad_catch()
Caught this error: ValueError('Represents a hidden bug, do not catch this',)

위에 소스를 한 번 보세요~ 출력 가능합니다. Value 에러가 먼저 잡히겠죠?
김재민님의 프로필 이미지
김재민

작성한 질문수

질문하기