mirror of
https://github.com/alrayyes/wiki.git
synced 2025-06-26 14:36:34 +00:00
Quartz sync: May 6, 2024, 10:40 PM
This commit is contained in:
parent
aee9145691
commit
4ef8371441
635 changed files with 22281 additions and 6 deletions
36
content/20201111094033-javascript_exceptions_finally.md
Normal file
36
content/20201111094033-javascript_exceptions_finally.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
id: 06ffac8f-e131-4a17-8c88-7edbe3bd0cfd
|
||||
title: JavaScript Exceptions Finally
|
||||
---
|
||||
|
||||
# Description
|
||||
|
||||
Code in `finally` block is **always** run after code in the `try` block:
|
||||
|
||||
# Syntax
|
||||
|
||||
``` javascript
|
||||
function baSays() {
|
||||
throw new Error("I pity the fool!")
|
||||
}
|
||||
|
||||
try {
|
||||
baSays()
|
||||
} catch (error) {
|
||||
console.log("This is the B.A. error: " + error)
|
||||
} finally {
|
||||
console.log("This code is always run!")
|
||||
}
|
||||
|
||||
function hannibalSays() {
|
||||
console.log("I love it when a plan comes together!")
|
||||
}
|
||||
|
||||
try {
|
||||
hannibalSays()
|
||||
} catch (error) {
|
||||
console.log("This is the Hannibal error: " + error)
|
||||
} finally {
|
||||
console.log("This code is always run!")
|
||||
}
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue