Wednesday, June 26, 2013

Answers of Concepts of Programming Languages Chapter 14

Review Questions
2. An exception is raised when its associated event occurs
3. Advantages to having exception handling built into a language :

  • Without exception handling, the code required to detect error conditions can considerably clutter a program
  • Save development costs, program size, and program complexity
7. All of them are gathered together in an exception clause
10. Four exceptions defined in the default package, Standard :
  • Constraint_Error
  • Program_Error
  • Storage_Error
  • Tasking_Error
11. Yes
12. Disabling run-time checks
13. Problems with Ada's exception handling :
  • the propagation model
  • the inadequacy of exception handling for tasks
  • when supporting OOP, its exception handling was not extended to deal with the new constructs
15. Container classes
16. Math library functions
18. After a handler has completed its execution, control flows to the first statement following the try construct

Problem Set
1. The early programming languages, when the error occurs, the error is transferred to the operating system. The typical OS reaction to a run-time error is to display a diagnostic message.
2. Java compilers usually generate code to check the correctness of every subscript expression. In C subscript ranges are not checked because the cost of such checking was not believed to be worth the benefit of detecting such errors
4. Three alternatives for dealing with checked exception in Java :
  • It can catch the exception and handle it
  • It can catch the exception and throw an exception that is listed in its own throws clause
  • It could declare the exception in its own throws clause and not handle it, which effectively propagates the exception to an enclosing try clause, if there is one, or to the method's caller, if there is no enclosing try clause.

No comments:

Post a Comment