The purpose of this quiz is to give you a chance to focus your knowledge of simple exception handling in C++.
When dealing with exceptions in C++, we have three new keywords:
When calling code that might throw an exception, we should try to execute it and then catch any possible exception(s).
TRUE✓ | FALSE✗ | exceptions are meant to handle extreme situations. |
---|---|---|
TRUE✗ | FALSE✓ | For instance, many string class methods use them to report invalid capitalization of data. |
Let's say you were going to access the 5th position in a string entered by the user earlier in the program. Show how to do this with care to avoid any possible crash of the program were there to not be a 5th position in the string after all.
try { letter = str_var.at(4); } catch (out_of_range ex) { cout << "\nThat text wasn't long enough!\n"; }
TRUE✗ | FALSE✓ | You can put only one statement inside a try block. |
---|---|---|
TRUE✓ | FALSE✗ | The syntax ... can be placed in the catch block's parentheses to catch any exception the try block's code may throw. |