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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 4개는 보이지 않습니다)
3번째 줄: 3번째 줄:
;try except
;try except


==C#==
==JavaScript==
[[category:csharp]]
[[category: JavaScript]]
<source lang='csharp'>
<syntaxhighlight lang='JavaScript'>
try {
try {
  line = console.readLine();
     asdfasdf("Welcome guest!");
  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) {
catch(err) {
  console.printLine("Hello!");
    console.log( err.message );
}
}
catch (Exception e) {
</syntaxhighlight>
  console.printLine("Error: " + e.message());
* 새로운 블럭을 만들지 않고 .then, .catch로도 대체할 수 있습니다.
}
finally {
  console.printLine("The program terminates now");
}
</source>


==Python==
==Python==
[[category:python]]
[[category:python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
try:
try:
try:
try:
38번째 줄: 26번째 줄:
print('IOError')
print('IOError')
# IOError
# IOError
</source>
</syntaxhighlight>
<source lang='Python'>
<syntaxhighlight lang='Python'>
try:
try:
try:
try:
48번째 줄: 36번째 줄:
print('IOError')
print('IOError')
# ZeroDivisionError
# ZeroDivisionError
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[finally]]
*[[예외 처리]]
*[[예외 처리]]
*[[예외 처리 구문]]
*[[예외 처리 구문]]

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

try-catch, throw
try except

1 JavaScript[ | ]

try {
    asdfasdf("Welcome guest!");
}
catch(err) {
    console.log( err.message );
}
  • 새로운 블럭을 만들지 않고 .then, .catch로도 대체할 수 있습니다.

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