June 28, 2013

KBP Chapter 14

6. What is exception propagation in Ada?
-Exception propagation allows an exception raised in one program unit to be handled in some other unit in its dynamic or static ancestry. This allows a single exception handler to be used for any number of different program units. This reuse can result in significant savings in development cost, program size, and program complexity.
9. What is the scope of exception handlers in Ada?
-Exception handlers can be included in blocks or in the bodies of subprograms, packages, or tasks.
10. What are the four exceptions defined in the Standard package of Ada?
-There are four exceptions that are defined in the default package, Standard:
- Constraint_Error
- Program_Error
- Storage_Error
- Tasking_Error

11. Are they any predefined exceptions in Ada?
12. What is the use of Suppress pragma in Ada? 
-The suppress pragma is used to disable certain run-time checks that are parts of the built-in exceptions in Ada.
14. What is the name of all C++ exception handlers?
-Try clause.
30. In which version were assertions added to Java?
-Assertions were added to Java in version 1.4.
31. What is the use of the assert statement?
-The assert statement is used for defensive programming. A program may be written with many assert statements, which ensure that the program’s computation is on track to produce correct results.
32. What is event-driven programming?
-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. What is the purpose of a Java JFrame?
-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.
34. What are the different forms of assert statement?
-There are two possible forms of the assert statement:
 a.assert condition;
 b.assert condition : expression;
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.
6.In languages without exception-handling facilities, it is common to have most subprograms include an “error” parameter, Which can be set to some values representing “OK” or some other value representing “error in procedure”. What advantage does a linguistic exception-handling facility like that of Ada have over this method?
-There are several advantages of a linguistic mechanism for handling exceptions, such as that found in Ada, over simply using a flag error parameter in all subprograms. One advantage is that the code to test the flag after every call is eliminated. Such testing makes programs longer and harder to read. Another advantage is that exceptions can be propagated farther than one level of control in a uniform and implicit way. Finally, there is the advantage that all programs use a uniform method for dealing with unusual circumstances, leading to enhanced readability.
7.In languages without exception-handling facilities, we could send an error-handling procedure as parameter to each procedure that can detect errors than must be handled. What disadvantage are there to this method?
- There are several disadvantages of sending error handling subprograms to other subprograms. One is that it may be necessary to send several error handlers to some subprograms, greatly complicating both the writing and execution of calls. Another is that there is no method of propagating exceptions, meaning that they must all be handled locally. This complicates exception handling, because it requires more attention to handling in more places.
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.