Catch and Report Any Task
Catch and Report Any Task
Write void catchAndReport(void (*task)(), const std::string& label), a safety net around a function it knows nothing about. It calls task() inside a try block and prints exactly one line:
- when the task finishes normally: the label, then : ok
- when the task throws anything derived from std::exception: the label, then : failed (, what() and )
- when the task throws anything else: the label, then : failed (unknown error)
No exception may escape catchAndReport. The tests define a few tasks of their own (one prints and returns, one throws a std::runtime_error, one throws a plain int, one throws a std::logic_error), call catchAndReport for each with a label, and print all tasks reported at the end.
Do NOT write a main function.
Expected Output:
copying files backup: ok upload: failed (no connection) cleanup: failed (unknown error) verify: failed (checksum mismatch) all tasks reported
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...