Learn JavaScript
Error Handling
36.3
Lesson

Synchronous working of try...catch

If we want to catch the errors that occur in scheduled code like setTimeout, then we must include try...catch inside that function.

In the example given below, the try {...} block is placed inside the setTimeout. It catches the errors that occur in the code.

If we place the setTimeout inside the try... bock, it will not be able to catch the errors.