Practice Programs can generally be solved with a short program that directly applies the programming principles presented in this chapter.
The Standard Template Library includes a class named exception that is the parent class for any exception thrown by an STL function. Therefore, any exception can be caught by this class. The following code sets up a try-catch block for STL exceptions:
#include#include #include using namespace std;int main(){ string s = "hello";try{ cout << "No exception thrown." << endl;}catch (exception& e){ cout << "Exception caught: " << e.what() << endl;}return 0;}
Modify the code so that an exception is thrown in the try block. You could try accessing an invalid index in a string using the at member function.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.