Real programs hit bad input, missing files, impossible math. C++ offers a controlled escape hatch.
1 throw
Raise an error object right away — the normal flow stops on the spot.
2 try
Wrap the risky code in a guarded block so a throw inside can be caught.
3 catch
Receives the thrown value and handles it — the program carries on instead of crashing.
4 std::thread
A first taste of parallelism: a thread runs a function alongside main; join() waits for it.
When code meets trouble
throw1Raise an error object right away — the normal flow stops on the spot. try2Wrap the risky code in a guarded block so a throw inside can be caught. catch3Receives the thrown value and handles it — the program carries on instead of crashing. std::thread4A first taste of parallelism: a thread runs a function alongside main; join() waits for it. 4 building blocks make up When code meets trouble
Follow the token: normal path — until the error check says yes and the catch block rescues it.
process decision input / output start / end What actually happens between the throw and the next normal line — stage by stage.
Press play — the throw jumps straight out of the try block into catch, and main still finishes.
preprocessThe preprocessor pastes in iostream for cout.
Memory
no variables yet — press play
Console
output appears as the program runs…
Click a term, then click its description to lock the pair.
5 conceptsTap a card to expand ?try { }drops into place
?throwdrops into place
?catch (int e)drops into place
?std::thread t(f)drops into place
?t.join()drops into place
01try wraps risky code; throw raises an error; catch handles it.
02After a catch, the program continues — no crash.
03Code between the throw and the catch is skipped, not run.
04std::thread plus join() means parallel work with a clean wait at the end.
05Handle what you can, throw what you cannot.