Problem 1
Mark the following statements as true or false.
a. The order in which catch blocks are listed is not important.
b.
Problem 2
What is the difference between a try block and a catch block?
Problem 3
What will happen if an exception is thrown but not caught?
Problem 4
What happens if no exception is thrown in a try block?
Problem 6
Consider the following
Problem 8
Consider the following C++ code: int lowerLimit; . . . try { cout << "Entering the try block." << endl; if (lowerLimit < 100) throw exception("Lower limit violation."); cout << "Exiting the try block." << endl; } catch (exception eObj) { cout << "Exception: " << eObj.what() << endl; } cout << "After the catch block" << endl; What is the output if: a. The value of lowerLimit is 50? b. The value of lowerLimit is 150?
Problem 9
Consider the following C++ code: int lowerLimit; int divisor; int result; try { cout << "Entering the try block." << endl; if (divisor == 0) throw 0; if (lowerLimit < 100) throw string("Lower limit violation."); result = lowerLimit / divisor; cout << "Exiting the try block." << endl; } catch (int x) { cout << "Exception: " << x << endl; result = 120; } catch (string str) { cout << "Exception: " << str << endl; } cout << "After the catch block" << endl; What is the output if: a. The value of lowerLimit is 50, and the value of divisor is 10? b. The value of lowerLimit is 50, and the value of divisor is 0? c. The value of lowerLimit is 150, and the value of divisor is 10? d. The value of lowerLimit is 150, and the value of divisor is 0?
Problem 10
If you define your own exception class, what typically is included in that class?
Problem 11
What type of statement is used to rethrow an exception?
Problem 12
Define an exception class called tornadoException. The class should have two
constructors, including the default constructor. If the exception is thrown
with the default constructor, the method what should return "Tornado: Take
cover immediately!". The other constructor has a single parameter, say,