CJCoding With Joseph

Rethrowing Exceptions

Write two functions that demonstrate logging and rethrowing an exception:

1. loadFile(const string& filename): if filename is empty, throw a std::runtime_error with "Empty filename". Otherwise print "Loading: " followed by filename.

2. openDocument(const string& filename): calls loadFile inside a try block. If a runtime_error is caught, print "[LOG] " followed by e.what(), then rethrow the same exception using throw; (bare throw with no argument).

The caller of openDocument handles 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.