Skip to content

Commit a7eacb2

Browse files
committed
update for try-catch-finally
1 parent 6983810 commit a7eacb2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

challenges/primitives.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ num1 > 0 || num2 < 0 // true
198198
const num1 = 10, num2 = 20;
199199

200200
true && false; // false
201-
false && false; // true
201+
false && false; // false
202202
true && num1; // 10
203203
num1 && num2; // 20
204204
"text" && (num1 + num2) // 30
@@ -815,21 +815,22 @@ myTag`Note: ${person} is a member of following communities: ${membership}`;
815815
### Write a code to show the working of `try...catch...finally`
816816
817817
- The `try` statement consists of a try-block, which contains one or more statements. At least one catch-block, or a finally-block, must be present
818-
- The exceptions and errors in from try block are caught in catch block
818+
- The exceptions and errors from try block are caught in catch block
819819
820820
```js
821821
try {
822-
// statements
823-
throw new Error("Unexpected error");
822+
callAPI(); // It will throw an Error
824823
} catch (error) {
825-
// statements
824+
throw new Error(error); // ReferenceError: callAPI is not defined
826825
} finally {
827-
// statements
826+
console.log("I will execute no matter what happened in try or catch");
828827
}
829828
```
830829
831830
###### Notes
832-
`try` can be chained with `catch` block or `finally` block
831+
832+
- `try` can be chained with `catch` block or `finally` block
833+
- `try..catch` only works synchronously and for runtime errors
833834
834835
###### References
835836
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch

0 commit comments

Comments
 (0)