Skip to content

Commit baec9dd

Browse files
committed
translate(ko): Error Handling
1 parent 936cf2c commit baec9dd

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,16 +2327,14 @@ try {
23272327

23282328
## μ—λŸ¬ 처리
23292329

2330-
Thrown errors are a good thing! They mean the runtime has successfully identified when something in your program has gone wrong and it's letting you know by stopping function
2331-
execution on the current stack, killing the process (in Node), and notifying you in the console with a stack trace.
2330+
μ—λŸ¬λ₯Ό λ˜μ§€λŠ” 것은 쒋은 κ²ƒμž…λ‹ˆλ‹€! μ—λŸ¬λ₯Ό λ˜μ§„λ‹€λŠ” 것은 λŸ°νƒ€μž„μ΄ λ‹Ήμ‹ μ˜ ν”„λ‘œκ·Έλž¨μ—μ„œ λ­”κ°€ 잘λͺ»λ˜μ—ˆμ„ λ•Œ μ‹λ³„ν•˜κ³  ν˜„μž¬ μŠ€νƒμ—μ„œ ν•¨μˆ˜ 싀행을 λ©ˆμΆ”κ³ , (λ…Έλ“œμ—μ„œ) ν”„λ‘œμ„ΈμŠ€λ₯Ό μ’…λ£Œν•˜λ©°, μŠ€νƒ 트레이슀λ₯Ό μ½˜μ†”μ— λ³΄μ—¬μ€ŒμœΌλ‘œμ¨ λ‹Ήμ‹ μ—κ²Œ ν•΄λ‹Ή μ—λŸ¬λ₯Ό μ•Œλ €μ£ΌλŠ” 것을 μ˜λ―Έν•©λ‹ˆλ‹€.
23322331

2333-
### Always use Error for throwing or rejecting
2332+
### `throw` λ˜λŠ” `reject` κ΅¬λ¬Έμ—μ„œ 항상 `Error` νƒ€μž…μ„ μ‚¬μš©ν•˜μ„Έμš”
23342333

2335-
JavaScript as well as TypeScript allow you to `throw` any object. A Promise can also be rejected with any reason object.
2336-
It is advisable to use the `throw` syntax with an `Error` type. This is because your error might be caught in higher level code with a `catch` syntax.
2337-
It would be very confusing to catch a string message there and would make
2338-
[debugging more painful](https://basarat.gitbook.io/typescript/type-system/exceptions#always-use-error).
2339-
For the same reason you should reject promises with `Error` types.
2334+
νƒ€μž…μŠ€ν¬λ¦½νŠΈλΏλ§Œ μ•„λ‹ˆλΌ μžλ°”μŠ€ν¬λ¦½νŠΈλŠ” μ–΄λ–€ 객체든지 μ—λŸ¬λ₯Ό `throw` ν•˜λŠ” 것을 ν—ˆμš©ν•©λ‹ˆλ‹€. λ˜ν•œ, ν”„λ‘œλ―ΈμŠ€λŠ” μ–΄λ–€ 객체라도 거뢀될 수 μžˆμŠ΅λ‹ˆλ‹€.
2335+
`Error` νƒ€μž…μ—λŠ” `throw` ꡬ문을 μ‚¬μš©ν•˜λŠ” 것이 λ°”λžŒμ§ν•©λ‹ˆλ‹€. λ‹Ήμ‹ μ˜ μ—λŸ¬κ°€ μƒμœ„ μ½”λ“œμ˜ `catch` κ΅¬λ¬Έμ—μ„œ 작힐 수 있기 λ•Œλ¬Έμž…λ‹ˆλ‹€.
2336+
λ¬Έμžμ—΄ λ©”μ‹œμ§€κ°€ μž‘νžˆλŠ” 것은 맀우 ν˜Όλž€μŠ€λŸ¬μš°λ©° μ΄λŠ” [디버깅을 더 κ³ ν†΅μŠ€λŸ½κ²Œ](https://basarat.gitbook.io/typescript/type-system/exceptions#always-use-error) λ§Œλ“­λ‹ˆλ‹€.
2337+
이와 같은 이유둜 당신은 `Error` νƒ€μž…μœΌλ‘œ ν”„λ‘œλ―ΈμŠ€λ₯Ό κ±°λΆ€ν•΄μ•Όν•©λ‹ˆλ‹€.
23402338

23412339
**Bad:**
23422340

@@ -2361,17 +2359,17 @@ function get(): Promise<Item[]> {
23612359
return Promise.reject(new Error('Not implemented.'));
23622360
}
23632361

2364-
// or equivalent to:
2362+
// λ˜λŠ” μ•„λž˜μ™€ λ™μΌν•©λ‹ˆλ‹€:
23652363

23662364
async function get(): Promise<Item[]> {
23672365
throw new Error('Not implemented.');
23682366
}
23692367
```
23702368

2371-
The benefit of using `Error` types is that it is supported by the syntax `try/catch/finally` and implicitly all errors have the `stack` property which
2372-
is very powerful for debugging.
2373-
There are also another alternatives, not to use the `throw` syntax and instead always return custom error objects. TypeScript makes this even easier.
2374-
Consider following example:
2369+
`Error` νƒ€μž…μ„ μ‚¬μš©ν•˜λŠ” μž₯점은 `try/catch/finally` ꡬ문에 μ˜ν•΄ μ§€μ›λ˜κ³  μ•”μ‹œμ μœΌλ‘œ λͺ¨λ“  μ—λŸ¬κ°€ 디버깅에 맀우 κ°•λ ₯ν•œ `stack` 속성을 κ°€μ§€κ³  있기 λ–„λ¬Έμž…λ‹ˆλ‹€.
2370+
또 ν•˜λ‚˜μ˜ λŒ€μ•ˆμ€ μžˆμŠ΅λ‹ˆλ‹€. `throw` ꡬ문을 μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” λŒ€μ‹ , 항상 μ‚¬μš©μž μ •μ˜ 객체λ₯Ό λ°˜ν™˜ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€.
2371+
νƒ€μž…μŠ€ν¬λ¦½νŠΈλŠ” 이것을 훨씬 더 μ‰½κ²Œ λ§Œλ“­λ‹ˆλ‹€.
2372+
μ•„λž˜μ˜ 예제λ₯Ό ν™•μΈν•˜μ„Έμš”:
23752373

23762374
```ts
23772375
type Result<R> = { isError: false, value: R };
@@ -2388,13 +2386,13 @@ function calculateTotal(items: Item[]): Failable<number, 'empty'> {
23882386
}
23892387
```
23902388

2391-
For the detailed explanation of this idea refer to the [original post](https://medium.com/@dhruvrajvanshi/making-exceptions-type-safe-in-typescript-c4d200ee78e9).
2389+
이 μ•„μ΄λ””μ–΄μ˜ μžμ„Έν•œ μ„€λͺ…은 [원문](https://medium.com/@dhruvrajvanshi/making-exceptions-type-safe-in-typescript-c4d200ee78e9)을 μ°Έκ³ ν•˜μ„Έμš”.
23922390

23932391
**[⬆ 맨 μœ„λ‘œ 이동](#λͺ©μ°¨)**
23942392

2395-
### Don't ignore caught errors
2393+
### 작힌 μ—λŸ¬λ₯Ό λ¬΄μ‹œν•˜μ§€ λ§ˆμ„Έμš”
23962394

2397-
Doing nothing with a caught error doesn't give you the ability to ever fix or react to said error. Logging the error to the console (`console.log`) isn't much better as often times it can get lost in a sea of things printed to the console. If you wrap any bit of code in a `try/catch` it means you think an error may occur there and therefore you should have a plan, or create a code path, for when it occurs.
2395+
작힌 μ—λŸ¬λ₯Ό λ°”λΌλ³΄λŠ” κ²ƒλ§ŒμœΌλ‘œλŠ” ν•΄λ‹Ή μ—λŸ¬λ₯Ό κ³ μΉ˜κ±°λ‚˜ λŒ€μ‘ν•  수 μ—†μŠ΅λ‹ˆλ‹€. μ½˜μ†”μ— μ—λŸ¬λ₯Ό κΈ°λ‘ν•˜λŠ” 것(`console.log`)은 μ½˜μ†”μ— 좜λ ₯된 λ§Žμ€ 것듀 μ‚¬μ΄μ—μ„œ λ°œκ²¬λ˜μ§€ λͺ»ν•  수 있기 λ•Œλ¬Έμ— κ·Έλ‹€μ§€ 쒋은 선택은 μ•„λ‹™λ‹ˆλ‹€. 당신이 μ–΄λ–€ μ½”λ“œλ₯Ό `try/catch`둜 κ°μŒŒλ‹€λ©΄, κ·Έ μ½”λ“œμ—μ„œ μ—λŸ¬κ°€ 일어날 수 있으며, 즉 μ—λŸ¬κ°€ λ°œμƒν–ˆμ„ λ•Œμ— λŒ€ν•œ κ³„νšμ΄λ‚˜ μž₯μΉ˜κ°€ μžˆμ–΄μ•Ό ν•œλ‹€λŠ” 것을 μ˜λ―Έν•©λ‹ˆλ‹€.
23982396

23992397
**Bad:**
24002398

@@ -2405,12 +2403,12 @@ try {
24052403
console.log(error);
24062404
}
24072405

2408-
// or even worse
2406+
// μ•„λž˜ μ˜ˆμ œλŠ” 훨씬 λ‚˜μ©λ‹ˆλ‹€.
24092407

24102408
try {
24112409
functionThatMightThrow();
24122410
} catch (error) {
2413-
// ignore error
2411+
// μ—λŸ¬λ₯Ό λ¬΄μ‹œ
24142412
}
24152413
```
24162414

@@ -2428,9 +2426,9 @@ try {
24282426

24292427
**[⬆ 맨 μœ„λ‘œ 이동](#λͺ©μ°¨)**
24302428

2431-
### Don't ignore rejected promises
2429+
### κ±°λΆ€λœ ν”„λ‘œλ―ΈμŠ€λ₯Ό λ¬΄μ‹œν•˜μ§€ λ§ˆμ„Έμš”
24322430

2433-
For the same reason you shouldn't ignore caught errors from `try/catch`.
2431+
μœ„μ™€ 같은 이유둜 `try/catch`λ‘œλΆ€ν„° 작힌 μ—λŸ¬λ₯Ό λ¬΄μ‹œν•˜λ©΄ μ•ˆλ©λ‹ˆλ‹€.
24342432

24352433
**Bad:**
24362434

@@ -2457,7 +2455,7 @@ getUser()
24572455
logger.log(error);
24582456
});
24592457

2460-
// or using the async/await syntax:
2458+
// λ˜λŠ” async/await ꡬ문을 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€:
24612459

24622460
try {
24632461
const user = await getUser();

0 commit comments

Comments
Β (0)