List various exceptional conditions that have occurred throughout this text. List as many additional exceptional conditions as you can. For each of these exceptions, describe briefly how a program typically would handle the exception, using the exception-handling techniques discussed in this chapter. Some typical exceptions are division by zero, arithmetic overflow, array subscript out of bounds, exhaustion of the free store, etc.
What will be an ideal response?
A few examples are: Division by zero—check the denominator to see if it is equal to zero, and throw an exception before the division occurs. Array subscript out of bounds—catch the exception, print an error message telling the user what index was trying to be referenced, and exit the program in a controlled manner. Exhaustion of the free store—catch the exception, and either deallocate enough other objects so that you can allocate memory for the new object or delete all objects and terminate the program. Bad cast—catch the exception and either cast the operand to the proper type, if that can be determined, or print an error message indicating what the bad cast
was, and exit the program.
You might also like to view...
To declare a class named A with two generic types, use
a. public class A
What is the affirmative interpretation of the First Amendment?
What will be an ideal response?
A method header is also called a(n) _____.
A. argument B. address C. statement D. declaration
Looks up a value in a vertical lookup table and returns a related result from the lookup table.
What will be an ideal response?