You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-9Lines changed: 32 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -2598,18 +2598,26 @@ try {
2598
2598
2599
2599
## Error Handling
2600
2600
2601
+
## 错误处理
2602
+
2601
2603
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
2602
2604
execution on the current stack, killing the process (in Node), and notifying you in the console with a stack trace.
@@ -2661,13 +2671,19 @@ function calculateTotal(items: Item[]): Failable<number, 'empty'> {
2661
2671
2662
2672
For the detailed explanation of this idea refer to the [original post](https://medium.com/@dhruvrajvanshi/making-exceptions-type-safe-in-typescript-c4d200ee78e9).
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.
0 commit comments