9 Tweets 3 reads Oct 02, 2022
Learn JavaScript try...catch...finally Statement🔥
Thread🧵
In programming, there can be two types of errors in the code:
Syntax Error: Error in the syntax.
Runtime Error: This type of error occurs during the program's execution.
For example, calling an invalid function or a variable.
The try, catch and finally blocks are used to handle exceptions.
JavaScript try...catch Statement
The `try...catch` statement is used to handle the exceptions.
Syntax -
How does it work?
The main code is inside the `try` block. While executing the `try` block, if any error occurs, it goes to the `catch` block. The `catch` block handles the errors as per the catch statements.
If no error occurs, the code inside the `try` block is executed and the `catch` block is skipped.
Display Undeclared Variable -
JavaScript try...catch...finally Statement
You can also use the `try...catch...finally` statement to handle exceptions. The `finally` block executes both when the code runs successfully or if an error occurs.
Syntax -
try...catch...finally
Example -
If you enjoyed reading this thread, please do the following:
1. Like the thread❤️
2. Retweet the first tweet.🔃
3. Follow me and enable notifications: ✅
@ajaysharma_dev
Thank you for reading all the way through.

Loading suggestions...