Skip to content

Commit 93b2aa1

Browse files
kbparkViolet-Bora-Lee
authored andcommitted
[번역]Part1 10.1 오류 다시 던지기 추가된 영문 번역
1 parent 147cd16 commit 93b2aa1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

1-js/10-error-handling/1-try-catch/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,17 @@ try {
355355

356356
위에선 '불완전한 데이터'를 다루려는 목적으로 `try..catch`를 썼습니다. 그런데 `catch`는 원래 `try` 블록에서 발생한 *모든* 에러를 잡으려는 목적으로 만들어졌습니다. 그런데 위 예시에서 `catch`는 예상치 못한 에러를 잡아내 주긴 했지만, 에러 종류와 관계없이 `"JSON Error"` 메시지를 보여줍니다. 이렇게 에러 종류와 관계없이 동일한 방식으로 에러를 처리하는 것은 디버깅을 어렵게 만들기 때문에 좋지 않습니다.
357357

358-
To avoid such problems, we can employ the "rethrowing" technique. The rule is simple:
358+
이런 문제를 피하고자 '다시 던지기(rethrowing)' 기술을 사용합니다. 규칙은 간단합니다.
359359

360-
**Catch should only process errors that it knows and "rethrow" all others.**
360+
**catch는 알고 있는 에러만 처리하고 나머지는 '다시 던져야' 합니다.**
361361

362-
The "rethrowing" technique can be explained in more detail as:
362+
'다시 던지기' 기술을 더 자세히 설명하겠습니다.
363363

364-
1. Catch gets all errors.
365-
2. In the `catch(err) {...}` block we analyze the error object `err`.
366-
3. If we don't know how to handle it, we do `throw err`.
364+
1. catch가 모든 에러를 받습니다.
365+
2. `catch(err) {...}` 블록 안에서 에러 객체 `err`를 분석합니다.
366+
3. 에러 처리 방법을 알지 못하면 `throw err`를 합니다.
367367

368-
Usually, we can check the error type using the `instanceof` operator:
368+
보통 에러 타입을 `instanceof` 명령어로 체크합니다.
369369

370370
```js run
371371
try {
@@ -374,12 +374,12 @@ try {
374374
*!*
375375
if (err instanceof ReferenceError) {
376376
*/!*
377-
alert('ReferenceError'); // "ReferenceError" for accessing an undefined variable
377+
alert('ReferenceError'); // 정의되지 않은 변수에 접근하여 'ReferenceError' 발생
378378
}
379379
}
380380
```
381381

382-
We can also get the error class name from `err.name` property. All native errors have it. Another option is to read `err.constructor.name`.
382+
`err.name` 프로퍼티로 에러 클래스 이름을 알 수도 있습니다. 기본형 에러는 모두 `err.name` 프로퍼티를 가집니다. 또는 `err.constructor.name`를 사용할 수도 있습니다.
383383

384384
에러를 다시 던져서 `catch` 블록에선 `SyntaxError`만 처리되도록 해보겠습니다.
385385

0 commit comments

Comments
 (0)