Concepts of Programming Languages ---- Chapter 14 Exception Handling and Event Handling
Name : Fandy Limardi
NIM : 1601210713
Lecture : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment : Concept of programming languages ---- Chapter 14 Exception Handling and Event Handling
1. Define functional form, simple list, , and referential transparency.
A higher-order function, or functional form, is one that either takes one or more functions as parameters or yields a function as its result, or both. A simple list is the problem of membership of a given atom in a given list that does not include sublists. A bound variable is a variable that never changes in the expression after being bound to an actual parameter value at the time evaluation of the lambda expression begins. A referential transparency is the execution of a function always produces the same result when given the same parameters
An exception is raised when its associated event occurs.
6. Explain in which the arithmetic processing capabilities of LISP and Prolog are similar.
Arithmetic processing is simple to implement in LISP and Prolog.
7. What does the abbreviation REPL stand for?
REPL stand for read-evaluate-print loop
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.
There are four exceptions that are defined in the default package, Standard:
Yes, they are.
14. What is the name of all C++ exception handlers?
The exception overflow_error is thrown by math library functions.
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.
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:
· assert condition;
· 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 value 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.