โ 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
Topics:
FunctionsExceptions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.