Skip to content
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
차이점은 함수 내부의 코드를 보면 분명해집니다.

<<<<<<< HEAD
`try..catch`에 '빠져나오게 하는' 코드가 있다면 함수의 행동이 달라집니다.

아래 예시와 같이 `try..catch` 내부에 `return`이 있을 때가 대표적인 예입니다. `finally` 절은 `return`문을 통해 `try..catch`를 빠져나가는 경우를 포함하여 `try..catch`가 종료되는 *모든* 상황에서 실행됩니다. `try..catch`가 종료되었지만, 함수 호출 코드가 제어권을 갖기 직전에 실행되죠.
=======
The behavior is different if there's a "jump out" of `try...catch`.

For instance, when there's a `return` inside `try...catch`. The `finally` clause works in case of *any* exit from `try...catch`, even via the `return` statement: right after `try...catch` is done, but before the calling code gets the control.
>>>>>>> upstream/master
아래 예시와 같이 `try..catch` 내부에 `return`이 있을 때가 대표적인 예입니다. `finally` 절은 `return`문을 통해 `try..catch`를 빠져나가는 경우를 포함하여 `try..catch`가 종료되는 _모든_ 상황에서 실행됩니다. `try..catch`가 종료되었지만, 함수 호출 코드가 제어권을 갖기 직전에 실행되죠.

```js run
function f() {
Expand All @@ -32,15 +26,9 @@ f(); // cleanup!
```js run
function f() {
try {
<<<<<<< HEAD
alert('시작');
throw new Error("에러 발생!");
} catch (e) {
=======
alert('start');
throw new Error("an error");
} catch (err) {
>>>>>>> upstream/master
// ...
if("에러를 핸들링 할 수 없다면") {
*!*
Expand Down
20 changes: 0 additions & 20 deletions 1-js/10-error-handling/1-try-catch/1-finally-or-code-after/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,26 @@ importance: 5

두 코드 조각을 비교해보세요.

<<<<<<< HEAD
1. 첫 번째 코드 조각은 `try..catch` 이후에 코드를 실행하기 위해 `finally`를 사용하였습니다.

```js
try {
작업
} catch (e) {
에러 핸들링
=======
1. The first one uses `finally` to execute the code after `try...catch`:

```js
try {
work work
} catch (err) {
handle errors
>>>>>>> upstream/master
} finally {
*!*
작업 내역 삭제
*/!*
}
```
<<<<<<< HEAD
2. 두 번째 코드 조각에선 `try..catch` 바로 아래에 작업 내역을 삭제하는 코드를 놓았습니다.

```js
try {
작업
} catch (e) {
에러 핸들링
=======
2. The second fragment puts the cleaning right after `try...catch`:

```js
try {
work work
} catch (err) {
handle errors
>>>>>>> upstream/master
}

*!*
Expand Down
Loading