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.

Computer Science & Information Technology

You might also like to view...

In which of the following layers of the OSI model would MAC addressing be found?

A. Network B. Application C. Data Link D. Transport

Computer Science & Information Technology

JavaScript is an object-based programming language that involves working with the properties and methods associated with objects.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology