Recall & Review
beginner
What is the purpose of a try–catch block in C++?
A try–catch block is used to handle exceptions (errors) that may occur during program execution, allowing the program to continue running or handle the error gracefully instead of crashing.
Click to reveal answer
beginner
What keyword starts a block of code where exceptions might occur?
The try keyword starts a block of code where exceptions might be thrown.
Click to reveal answer
beginner
What keyword is used to catch and handle exceptions thrown in the try block?
The catch keyword is used to define a block that handles exceptions thrown in the try block.
Click to reveal answer
intermediate
How do you catch different types of exceptions in C++?
You can write multiple catch blocks after a try block, each specifying a different exception type to handle different errors separately.
Click to reveal answer
intermediate
What happens if an exception is thrown but not caught in a try–catch block?
If an exception is thrown and not caught, the program will terminate and may display an error message or crash.
Click to reveal answer
Which keyword begins the block where exceptions are tested in C++?
✗ Incorrect
The try block is where you put code that might throw exceptions.
What does the catch block do?
✗ Incorrect
The catch block handles exceptions thrown in the try block.
How can you handle multiple exception types?
✗ Incorrect
Multiple catch blocks allow handling different exception types separately.
What happens if no catch block matches the thrown exception?
✗ Incorrect
If no catch block matches, the program terminates due to an uncaught exception.
Which keyword is used to throw an exception in C++?
✗ Incorrect
The throw keyword is used to signal an exception.
Explain how a try–catch block works in C++ and why it is useful.
Think about what happens when an error occurs and how the program can respond.
You got /4 concepts.
Describe how you can handle different types of exceptions using try–catch blocks.
Consider how you might want to respond differently to different errors.
You got /3 concepts.