Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. What is the difference between a try block and a catch block? 2. Consider the following C++ code: double balance; try { cout <

1. What is the difference between a try block and a catch block?

2. Consider the following C++ code:

double balance;

try { cout << "Enter the balance: "; cin >> balance; cout << endl;

if (balance < 1000.00) throw balance;

cout << "Leaving the try block." << endl; } catch (double x)

{ cout << "Current balance: " << x << endl << "Balance must be greater than 1000.00" << endl; }

In this code, identify the try block.

In this code, identify the catch block.

In this code, identify the catch block parameter and its type.

In this code, identify the throw statement.

3. If you define your own exception class, what is typically included in that class?

4. Suppose the exception class myException is defined as follows:

class myException { public: myException() { message = "myException thrown!"; cout << "Immediate attention required!" << endl; }

myException(string msg) { message = msg; cout << "Attention required!" << endl; }

string what() { return message; }

private: string message; }

Suppose that in a user program, the catch block has the following form:

catch (myException mE) { cout << mE.what() << endl; }

a. What output will be produced if the exception is thrown with the default constructor?

b. Also, what output will be produced if the exception is thrown with the constructor with parameters with the following actual parameter? "May Day, May Day"

5. Name three exception-handling techniques.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Which are non projected Teaching aids in advance learning system?

Answered: 1 week ago