Module 10 · Error Handling: throw, try, catch, finally, and Reading a Stack Trace
Errors Under the Hood: Completion Records, the Cost of try, and What Building an Error Really Costs
ProReading
Maria has heard two pieces of advice from older programmers. One: "never put try inside a hot loop, it kills performance". Two: "exceptions are expensive, avoid them". She wants to know if either is still true on Node 22. She also wants to know why finally can change what a function returns, which looked like magic in Lesson 02.
Checking what this lesson needs for you…
What is inside Errors Under the Hood: Completion Records, the Cost of try, and What Building an Error Really Costs
- Completion records: how the specification sees a block
- Why that rule matters
- The cost of a try block on the normal path
- The cost of building an Error
- What this means in practice
- Error.stackTraceLimit: how many frames
- Error.captureStackTrace: put a stack on anything, or hide a frame