TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
JavaScript / Chapter 18 of 60~12 min • Beginner
Chapter 18JavaScript

Errors and exception handling

An exception interrupts normal execution. try runs code that may throw, catch handles an exception, and finally runs cleanup whether or not an exception occurred. Throw an Error with a useful message when appropriate.

How it works

Step-by-step walkthrough

  1. Create invalid JSON
  2. Catch the parsing error
  3. Run cleanup

Example

JavaScript
try {
  JSON.parse('not JSON');
} catch (error) {
  console.log('Invalid JSON');
} finally {
  console.log('Done');
}
Expected result: Invalid JSON, then Done
💡 Point to remember
Do not catch and silently ignore Playwright assertion failures.

✎ Your practice task

Replace the input with valid JSON.

Knowledge check

Which block is intended for unconditional cleanup?

🌐 Continue learning