Ch14ReplacementHWFile(1)

docx

School

Harvard University *

*We aren’t endorsed by this school

Course

161

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

1

Uploaded by HighnessBatMaster978

Report
1. What type of statements are placed in a try block? Any statements that may return an error or exception are placed inside a try block as well as the code that is executed if an error is not returned. 2. a) What is wrong with the following code? Also provide the correct code. cout << "Enter the balance: "; cin >> balance; cout << endl; if (balance < 1000.00) throw balance; cout << "Leaving the try block." << endl; This code is out of order. It also throws the exception but doesn’t have a catch statement. balance was presumably declared earlier in the code but if not then it would need to have a variable type declared. cout << "Enter the balance: "; try{ cin >> balance; cout << endl; if (balance < 1000.00){ throw balance;} cout << "Leaving the try block." << endl; } catch(int balance); 3. What must you provide if you define your own exception class? You must provide the expected exception/error type. 4. How many parameters can a catch block have? 1 5. What will happen if an exception is thrown but not caught? If it is not caught, a terminate function will terminate the program.
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help