Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 17

What happens to the automatic objects that have been constructed in a TRy block when that block thRows an exception?

Problem 18

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.

Problem 20

A program contains the statement throw; Where would you normally expect to find such a statement? What if that statement appeared in a different part of the program?

Problem 22

Why should exceptions not be used as an alternate form of program control?

Problem 23

Describe a technique for handling related exceptions.

Problem 24

Until this chapter, we have found that dealing with errors detected by constructors can be awkward. Exception handling gives us a better means of handling such errors. Consider a constructor for a string class. The constructor uses new to obtain space from the free store. Suppose new fails. Show how you would deal with this without exception handing. Discuss the key issues. Show how you would deal with such memory exhaustion with exception handling. Explain why the exception-handling approach is superior.

Problem 25

Suppose a program tHRows an exception and the appropriate exception handler begins executing. Now suppose that the exception handler itself throws the same exception. Does this create infinite recursion? Write a program to check your observation.

Problem 26

Use inheritance to create various derived classes of runtime, error. Then show that a catch handler specifying the base class can catch derived-class exceptions.

Problem 28

Write a program that generates and handles a memory-exhaustion exception. Your program should loop on a request to create dynamic memory through operator new.

Problem 31

Write a program that demonstrates several exception types being caught with the catch \((\ldots)\) exception handler.

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks