Try-catch-finally

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:31 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
try-catch-finally
try-except-finally


1 C#[ | ]

try {
  line = console.readLine();
 
  if (line.length() == 0) {
    throw new EmptyLineException("The line read from console was empty!");
  }
 
  console.printLine("Hello %s!" % line);
  console.printLine("The program ran successfully");
}
catch (EmptyLineException e) {
  console.printLine("Hello!");
}
catch (Exception e) {
  console.printLine("Error: " + e.message());
}
finally {
  console.printLine("The program terminates now");
}

2 Python[ | ]

try:
	1/0
except:
	print("Error")
finally:
	print(42)
# Error
# 42

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}