Skip to content

Latest commit

 

History

History
36 lines (23 loc) · 994 Bytes

README.md

File metadata and controls

36 lines (23 loc) · 994 Bytes

15. Errors and exceptions

Handle failure at useful boundaries.

Learn

  • throw
  • Error
  • try/catch/finally
  • validation

How it works

Throw an Error when a function cannot fulfill its contract. Catch errors where you can recover or present a helpful message; otherwise let them surface for debugging. Use finally for cleanup that must run whether work succeeds or fails.

Common mistake

Silently swallowing every error hides bugs and leaves users with unclear states.

Guided challenge

Write a parser that rejects invalid input with a clear error and show a friendly message to the user.

Run the example

Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.

Completion check

  • Explain the core idea in your own words without reading the code.
  • Change one input and predict the output before running it.
  • Test one boundary or failure case, then record what you changed.