Loading topic
Error object. This chapter covers the three properties you will rely on most, name, message, and stack, and shows where each one lives on the object.2 min readthrow and try/catch and have read the previous chapter on the name, message, and stack properties. In this chapter you will see which error types JavaScript already provides, what triggers each one, and when your own code should throw them.2 min readextends and super), throw and try/catch, and how to run code in Node.js or the browser console. It also builds on the previous chapters' coverage of name, message, and stack.2 min readError and calls super(message, options), as covered in the previous chapter. It also assumes you can run code in Node.js or a browser console.2 min readclass ... extends Error, call super(message, options), and set this.name. Here you will add structured fields to that class, so that the code handling the error can read facts directly instead of parsing the message text.2 min readsuper(message, options) and sets this.name. It also assumes you know how to add structured fields such as status to that class. Here you will combine those pieces into a small family of related error classes.2 min readtry/catch, async/await, and the HttpError and NotFoundError classes from the previous chapter. The topic is deciding, inside one catch block, which errors to handle and which to let through.2 min readError and passes arguments to super, as covered earlier. You should also be comfortable with try/catch.2 min readname, how to tell errors apart with instanceof, and how the cause option of the Error constructor works.2 min readcause option and rethrow it at a layer boundary, as covered in the previous chapters. It also uses generator functions (function* and yield) and for...of loops.2 min read{ cause } to the Error constructor and how wrapping errors at layer boundaries works. Here we look at the exact rules the constructor uses when it creates the cause property. These rules matter when you log, copy, or inspect errors.2 min readPromise.allSettled, async/await, and the cause option from earlier chapters. Sometimes one operation fails for several independent reasons at once. Examples include a batch of requests or a form with many invalid fields. Throwing only the first error hides the o2 min readcause option works, and how to walk a cause chain. Here you will turn an error and its causes into plain data that a JSON logger can store.2 min readsuper(message, options) and sets this.name, as covered earlier. It also assumes you have run code in Node.js or a Chromium-based browser console.2 min readError with class extends, how prototype chains decide instanceof, and what a transpiler such as TypeScript or Babel does. The earlier chapters relied on instanceof to tell errors apart. That only works if each error instance really has your class2 min readError, set name, add fields such as status, and check errors with instanceof. Here the question is a design one: when a new failure case comes up, should it get its own class, or a code value on an existing class?2 min read