• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

StopIteration 예외 처리

20.05.04 09:50 작성 조회수 277

0

안녕하세요 선생님, @12:58에서 cr1.send(100)을 했을 때 발생하는 StopIteration을 처리하기 위해선 예외처리가 필요한것 처럼 일반적으로 코루틴은 StopIteration 처리 문구를 넣어줘야하나요?

답변 1

답변을 작성해보세요.

2

일반적으로 StopIteration은 for문 next 등올 접근 시 내부적으로 처리가 되기 때문에 

코딩시에는 사용하실일이 거의 없는 것 같습니다.

명시적으로 사용하셔도 되는 부분입니다. 사용하기 나름입니다.

Now, normally you don't see StopIteration exceptions. The reason for this is that you usually consume generators inside for loops. A for statement will automatically call next over and over until StopIteration gets raised. It will catch and suppress the StopIteration exception for you, so you don't need to mess around with try/except blocks to deal with it.