0
0
C++programming~5 mins

Try–catch block in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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++?
Athrow
Btry
Ccatch
Dexcept
What does the catch block do?
AHandles an exception
BThrows an exception
CStarts the program
DEnds the program
How can you handle multiple exception types?
AUse multiple catch blocks
BUse multiple try blocks
CUse one catch block with no parameters
DUse if-else statements
What happens if no catch block matches the thrown exception?
AThe program continues normally
BThe exception is ignored
CThe exception is automatically handled
DThe program terminates
Which keyword is used to throw an exception in C++?
Atry
Bcatch
Cthrow
Dexcept
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.