We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Errors
C++Handle failures with return values, exceptions and explicit termination policies. Read the guarantees of an operation and choose an appropriate response.
This track uses C++. You can make it your practice mode to browse related content across the site.
4 exercises
Explore freely. Sign in to keep your progress.
Your learning sequence
- 1 Not solved yet. Zero is an answer Practice · Easy
- 2 Not solved yet. Catch exceptions without slicing their type Practice · Medium
- 3 Not solved yet. Declare non-throwing Buffer moves Practice · Medium
- 4 Not solved yet. Skip invalid fields without losing valid results Practice · Medium
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
When does the guard destructor run as this exception reaches the shown catch handler?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
#include <iostream>
#include <stdexcept>
struct Guard {
~Guard() { std::cout << "cleanup" << std::endl; }
};
int main() {
try {
Guard guard;
std::cout << "throw" << std::endl;
throw std::runtime_error("boom");
} catch (const std::exception& e) {
std::cout << "caught: " << e.what() << std::endl;
}
}