2013-06-27

Programming Language Concept (14)

Book : Concept of Programming Language

Page 665
Review Question

2.   An exception is raised when its associated event occurs.
 
3.   The advantages of having support for exception handling builtin to language:
• First, without exception handling, the code required to detect error conditions can considerably clutter a program.
• Another advantage of language support for exception handling results from exception propagation. Exception propagation allows an exception raised in one program unit to be handled in some other unit in its dynamic or static ancestry.
• A language that supports exception handling encourages its users to consider all of the events that could occur during program execution and how they can be handled. This approach is far better than not considering such possibilities and simply hoping nothing will go wrong.
 
9.   An exception handler in Ada can occur in either a  subprogram body, a package body, a task, or a block
 
10.  There are four exceptions that are defined in the default package, Standard:
Constraint_aError
Program_Error
Storage_Error
Tasking_Error

 
12.   The suppress pragma is used to disable certain run-time checks that are parts of the built-in exceptions in Ada.
 
14. The name of all C++ exception handlers is Try clause.
 
15.  The exception out_of_range is thrown by library container classes.
 
16.  The exception overflow_error is thrown by math library functions.
 
32.  Event-driven programming is a programming where parts of the program are executed at completely unpredictable times, often triggered by user interactions with the executing program.
 
33.   The JFrame class defines the data and methods that are needed for frames. So, a class that uses a frame can be a subclass of JFrame. A JFrame has several layers, called panes.
 
Page 667  
Problem Set  
1.   What mechanism did early programming languages provide to detect or attempt to deal with errors?
Early programming languages were designed and implemented in such a way that the user program could neither detect nor attempt to deal with such errors. In these languages, the occurrence of such an error simply causes the program to be terminated and control to be transferred to the operating system.
 
2.   Describe the approach for the detection of subscript range errors used in C and Java.
In C subscript ranges are not checked. Java compilers usually generate code to check the correctness of every subscript expression. If any exception generates, then an unchecked exception is thrown.
 
4.   What are the different approaches to handle checked exception in Java?
In Java there are basically two types of exceptions: Checked exceptions and unchecked exceptions.
Checked exceptions must be explicitly caught or propagated as described in Basic try-catch-finally Exception Handling. Unchecked exceptions do not have this requirement. They don’t have to be caught or declared thrown.
Checked exceptions in Java extend the java.lang.Exception class. Unchecked exceptions extend the java.lang.RuntimeException.

 
14.  Summarize the arguments in favor of the termination and resumption models of continuation.
The resumption model is useful when the exception is only an unusual condition, rather than an error. The termination model is useful when the exception is an error and it is highly unlikely that the error can be corrected so that execution could continue in some useful way.

Tidak ada komentar:

Posting Komentar