← Back to Functions
Question 154
Rethrowing Exceptions
Rethrowing Exceptions
Write two functions that demonstrate logging and rethrowing an exception: 1.loadFile(const string& filename): iffilenameis empty, throw astd::runtime_errorwith"Empty filename". Otherwise print"Loading: "followed by filename. 2.openDocument(const string& filename): callsloadFileinside atryblock. If aruntime_erroris caught, print"[LOG] "followed bye.what(), then rethrow the same exception usingthrow;(bare throw with no argument). The caller ofopenDocumenthandles the final exception. Do NOT write a main function.
Expected Output:
Loading: report.pdf= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
FunctionsExceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.