Skip to content
try / catch / throw
step 1/5

Reading — step 1 of 5

Learn

~1 min readError Handling

Exceptions in JavaScript work like in most languages — throw raises one, try/catch handles it.

js

throw accepts any value, but throw Error instances (or subclasses) — they capture stack traces and play nicely with debuggers.

For async code, use try/catch around await:

js

finally runs whether you return, throw, or fall through. Useful for cleanup (close files, release locks).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…