Retry a Flaky Send Three Times
Retry a Flaky Send Three Times
The provided send(int attempt, int failures) throws a std::runtime_error("timeout") on the first failures attempts and prints sent on attempt with the attempt number after that. Build a retry loop around it:
- RetryError inherits from std::runtime_error; its explicit constructor takes a const std::string& message and passes it on
- int sendWithRetry(int failures, int maxAttempts): for attempt from 1 to maxAttempts, call send(attempt, failures) inside a try; when it succeeds, return the attempt number at once; when it throws std::runtime_error, print attempt , the number, failed: and what() on one line and continue with the next attempt. When every attempt has failed, throw RetryError with the text gave up after , maxAttempts and attempts.
The tests read pairs failures maxAttempts from input and print success after and the returned number, or error: and what() of the RetryError. For the first test the input is 2 3 then 5 3.
Do NOT write a main function.
Expected Output:
attempt 1 failed: timeout attempt 2 failed: timeout sent on attempt 3 success after 3 attempt 1 failed: timeout attempt 2 failed: timeout attempt 3 failed: timeout error: gave up after 3 attempts
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...