Вы находитесь на странице: 1из 2

[[Advances in Language Design]] $$ Exceptions and Exception Handlers: An exception is an event, which occurs during the execution of a program,

that disrupts the normal flow of the programs instructions. An exception is a hardware detected run-time error or unusual condition detected by software. Examples Arithmetic overflow End-of-file on input Wrong type for input data User define conditions Exception Handler (What is an Exception Handler?): Code executed when exception occurs. May need a different handler for each type of exception. Exceptions Handling:Exceptions are exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers. Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of some condition that changes the normal flow of execution. The condition is called an exception. When an error occurs with in a method, the method creates an object and hands it of to the runtime system. The object, called an exception object, contains information about the error; creating an exception object and handing it to the runtime system is called throwing an exception. After a method throws an exception, the runtime system attempts to find some thing to handle it. The set of possible some things to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the call stack.

Thus, exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special function called handlers. Because an exception handler is invoked without an explicit call, it ordinarily does not require a name or parameters. The definition of an exception handler typically contains only A set declarations of local variables (if any), and A sequence of executable statements.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

$$ CO-ROUTINES: Co-routines are subprograms that can return control to the caller before completion of execution. When a coroutine receives control from another subprogram, it executes partially and then is suspended when it returns control. At a later point, the calling program may resume execution of the co-routine from the point at which execution was previously suspended. 1

For ExampleIf A calls subprograms B as a co-routine, B executes awhile and returns control to A, just as any ordinary subprogram would do. When A again passes control to B via a resume B, B again executes awhile and returns control to A, Just as an ordinary subprogram. However, the situation is similar when viewed from subprogram B. B, in the middle of the execution, resume execution of A. A executes awhile and returns control to B. B continues execution awhile and return control to A. A continues execution awhile and returns control to B. From subprogram B, A appears much like an ordinary subprogram. The name co-routine derives from this symmetry, the two programs appear more as equals-two subprograms swapping control back and forth as each executes, with neither clearly controlling the other. Co-routines are execution context that exist concurrently, but that execute one at a time and that transfer control to each other explicitly, by name.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

* SCHEDULED SUBPROGRAMS * The concept of subprogram scheduling results from relaxation of the assumption that execution of a sub program should always be initiated immediately upon its call. One may think of an ordinary subprogram call statement as specifying that the called subprogram is to be scheduled for execution immediately, without completing execution of the calling program. Completion of execution of the calling program is rescheduled to occur immediately on termination of the subprogram. The exception-handling control structure may be viewed also as means of subprogram scheduling. Generalizing further, other subprogram scheduling techniques are possible: 1.Schedule subprograms to be executed before or after other subprograms, as, for example:call B after A, Which would schedule execution of subprogram B after execution of subprogram A is completed. 2.Schedule subprograms to be executed when an arbitrary Boolean expression becomes true, as, for example: call b when X = 5 and Z > 0 B is called whenever the values of Z and X are changed to satisfy the given conditions. 3.Schedule subprograms on the basis of a simulated time scale, for Example: call B at time = 25 Such scheduling allows a general interleaving of subprogram calls scheduled form different sources. 4.Schedule subprograms according to a priority designation, as, for example: Call B with priority 7 Which would active B when no other subprogram with higher priority has been scheduled. Concurrent execution: The Principal mechanism for installing parallel execution in a programming language is to create a construct that allows for parallel execution. The end statement performs this task: Satatement1 and statement2 andand statement n And has the semantics that each of the various statement execute in parallel; the statement following the and statement does not begin until all the parallel statements terminate. It provides the full parallel power we need for parallel execution. For Example:If an operating system consists of a task to read from a terminal, a task to write to a screen and a process to execute a user program, we could specify this operating system as:

Call Read Process and Call Write Process and Call Execute user program; ------------------------------------------------------------* END OF UNIT-II *----------------------------------------------2

Вам также может понравиться