Here's the pseudocode with exceptions: In C++, include for runtime_error.
The throw statement exits the function immediately.
The catch block runs only if an exception was thrown. You write catch (const runtime_error& e) to handle the specific error type. If no exception occurs, the catch block is skipped entirely.
Code after try-catch always runs.