Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yihan12 authored Dec 22, 2023
1 parent 176b9bf commit 3c9c46a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions javascript/Exception Handling/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# 异常处理

```javascript
try {
willGiveErrorSometime();
} catch (error) {
if (error instanceof RangeError) {
rangeErrorHandler(error);
} else if (error instanceof ReferenceError) {
referenceErrorHandle(error);
} else {
errorHandler(error);
}
}
```

### throw
> throw 语句用来抛出一个用户自定义的异常。当前函数的执行将被停止(throw 之后的语句将不会执行),并且控制将被传递到调用堆栈中的第一个 catch 块。如果调用者函数中没有 catch 块,程序将会终止。
Expand Down

0 comments on commit 3c9c46a

Please sign in to comment.