InterviewHubPRO
Section Overview
Q234

Question 234 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

45%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

What are the various statements in error handling

Below are the list of statements used in an error handling,

  1. try: This statement is used to test a block of code for errors
  2. catch: This statement is used to handle the error
  3. throw: This statement is used to create custom errors.
  4. finally: This statement is used to execute code after try and catch regardless of the result.

Practical Code Example

javascript
// Error Handling Statements:
try {
  throw new Error('Something went wrong!'); // throw statement
} catch (err) {
  console.error('Caught:', err.message);    // catch statement
} finally {
  console.log('Cleanup always executes');   // finally statement
}