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

(새 문서: ;try-catch, throw ==C#== category:csharp <source lang='csharp'> try { line = console.readLine(); if (line.length() == 0) { throw new EmptyLineException("The line read f...)
 
23번째 줄: 23번째 줄:
   console.printLine("The program terminates now");
   console.printLine("The program terminates now");
}
}
</source>
==Python==
[[category:python]]
<source lang='Python'>
try:
try:
open('.')
except ZeroDivisionError:
print('ZeroDivisionError')
except IOError:
print('IOError')
# IOError
</source>
<source lang='Python'>
try:
try:
1/0
except ZeroDivisionError:
print('ZeroDivisionError')
except IOError:
print('IOError')
# ZeroDivisionError
</source>
</source>


30번째 줄: 53번째 줄:
*[[점프문]]
*[[점프문]]
*[[C샵 키워드]]
*[[C샵 키워드]]
*[[finally]]

2014년 5월 18일 (일) 06:09 판

try-catch, throw

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:
	try:
		open('.')
	except ZeroDivisionError:
		print('ZeroDivisionError')
except IOError:
	print('IOError')
# IOError
try:
	try:
		1/0
	except ZeroDivisionError:
		print('ZeroDivisionError')
except IOError:
	print('IOError')
# ZeroDivisionError

3 같이 보기

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