"Try-catch-finally"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
6번째 줄: 6번째 줄:
==C#==
==C#==
[[category:csharp]]
[[category:csharp]]
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
try {
try {
   line = console.readLine();
   line = console.readLine();
26번째 줄: 26번째 줄:
   console.printLine("The program terminates now");
   console.printLine("The program terminates now");
}
}
</source>
</syntaxhighlight>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
try:
try:
1/0
1/0
39번째 줄: 39번째 줄:
# Error
# Error
# 42
# 42
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[try]]
*[[try]]
*[[throw]]
*[[throw]]

2020년 11월 2일 (월) 02:31 기준 최신판

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 }}