TRT
Sign in

Core · Module 8 · Lesson 1 of 5

Throwing and Catching: try, catch and throw

Signal failures with exceptions, catch them by const reference in the right order, and keep throwing code safe with RAII.

Pro — members onlyAbout 9 minutes

By the end you can

  • Throw and catch standard and custom exceptions correctly
  • Order catch clauses from most to least specific
  • Explain why throwing across raw owning pointers leaks

Builds on vector: The Default Container and How It Grows.

01 · A question first

A loan function fails deep inside a search, inside a checkout, inside a menu loop. Returning an error code means every layer checks and forwards it. What if the failure could jump straight to the one place that knows what to do, cleaning up everything on the way?

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Start with the problem
  • How the idea works
  • Why it is correct
  • What it costs
  • Pitfalls and variations
  • How a guard keeps throws safe
  • Where it is used

03 · Practice

Something wrong with this lesson? Report a problem