Loading topic
name, message, and stack properties.3 min readthrow to raise one. Here you will learn what happens to control flow when an error is thrown inside a try block, and how a catch block lets your program recover instead of stopping.2 min readtry and catch work, can write functions, and can run scripts in Node.js or the browser console. It covers the third clause of a try statement: finally.2 min readname and message, how to use throw, and how to catch errors with try and catch. Those topics come from the earlier chapters.2 min readextends and super. It also assumes you have read the earlier chapters on Error objects, throw, and the built-in error types.2 min readtry/catch works and how to define a custom error class that extends Error. Both topics were covered in earlier chapters.2 min readtry and catch work and how to check an error with instanceof before rethrowing it. Here we look at a small piece of syntax added in ES2019. It lets you write a catch clause without naming the error.2 min readtry/catch blocks, define classes that extend Error, and check errors with instanceof. It shows how to add context to a low-level error without losing the original.2 min readtry and catch work for synchronous code, and that you have used callback functions with setTimeout or event listeners. It explains a common surprise: a try block wrapped around code that schedules work does not protect the work itself.2 min read.then(), and that you have read the previous chapter on why try/catch cannot see errors thrown in callbacks that run later. All examples run as-is in Node.js or a browser console.2 min read.catch() handles a rejection. You should also be comfortable writing async functions and using await. The code runs in Node.js 18 or later, or in a browser console.2 min readtry/catch works, how promise rejections reach .catch(), and how to run a script in the browser console or with Node.js.2 min readtry/catch works, how to check a caught error with instanceof and rethrow it, how to wrap an error with cause, and how global handlers work. Those tools are covered in earlier chapters. This chapter is about deciding where in your code to use each of them.3 min read