Skip to content

Commit cb2659b

Browse files
authored
Merge pull request sadanandpai#4 from faran4engg/try-catch-update
fix: update for try-catch-finally
2 parents a7bdd7b + 5b8e755 commit cb2659b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

challenges/primitives.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,21 +815,21 @@ 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
```
830-
831829
###### Notes
832-
`try` can be chained with `catch` block or `finally` block
830+
831+
- `try` can be chained with `catch` block or `finally` block
832+
- `try..catch` only works synchronously and for runtime errors
833833
834834
###### References
835835
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch

0 commit comments

Comments
 (0)