Exception Handling and Multithreading

Lesson 17 of 20

When things go wrong, throw and catch gracefully — then peek at std::thread doing two jobs at once.

The big picture

When code meets trouble

Real programs hit bad input, missing files, impossible math. C++ offers a controlled escape hatch.

throw

Raise an error object right away — the normal flow stops on the spot.

try

Wrap the risky code in a guarded block so a throw inside can be caught.

catch

Receives the thrown value and handles it — the program carries on instead of crashing.

std::thread

A first taste of parallelism: a thread runs a function alongside main; join() waits for it.