Topical Information

The purpose of this quiz is to give you a chance to focus your knowledge of simple exception handling in C++.

Question Set Information

Questions

  1. When dealing with exceptions in C++, we have three new keywords:

    1. attemptNO
    2. tryYES
    3. throwYES
    4. hurlNO
    5. catchYES
  2. When calling code that might throw an exception, we should try to execute it and then catch any possible exception(s).

  3.  
    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.
  4. 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";
        }
    
    
  5.  
    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.