During execution of a program, events or conditions often occur that might be considered exceptional. Rather than continue with normal program execution, a subprogram needs to be called to perform some special processing, including being able to handle the following situations.
- Error conditions : To process an error such as an arithmetic operation overflow or reference to an array element with a subscript out of bounds.
- Unpredictable conditions That arise during normal program execution such as production of special output headings at the end of a pointer page or an end-of-file indicator on an input file.
- Tracing and monitoring during program testing. Such as printing trace output during program testing when the value of a variable changes.
Exception 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 of declarations of local variables &
- A sequence of executable statements.
Exception are processed in C++ and java via try clause. C++ raises an exception by throwing the exception, and the exception is handled by catching the exception.
try {
statement1 ;
statement2 ;
-----------
if Bad condition ( throw Exception Name } ;
}
Catch ExceptionName{ // Do something for Exception }
} // End of Exception.
}
Syntax of try and catch block.
# Propagating an exception :-> Generally an error is handled with in the same program but when an exception is not handled by the same program by the some other program is known as propagating an error.
One important effect of this rule is that it allows a subprogram to remain as a programmer defined abstract operation even in processing exceptions.
If the exception us handled within the subprogram then the subprogram returns in the normal way, and the caller is never aware that an exception has been raised.
Assertions :-> It is almost like an exception. An assertion is simply a statement implying a relation among data objects in a program, as in the C++ statement
#include<assert.h>
---------
---------
assert( x > y+1) ;
It will work like if ( x > y+1 ) ; /* Print error message */
# Coroutine :-> A program that return to their calling program before completion of execution such subprogram are termed coroutines.
When a co-routine receives control form another subprogram, it executes partially and then is suspended when it returns control. At later point, the calling program may resume execution of the coroutine from the point at which execution was previously suspended.
Suppose if A calls subprogram B as a coroutine, B executes awhile and return 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. Thus, to A, B appears as an ordinary subprogram. However, the situation is similar when viewed from subprogram B. B in the middle of the execution,resumes execution of A. A executes a while and return control to B. B continues execution a while and returns control to A. A executes awhile and returns control to B. From subprogram B, A appears much like an ordinary subprogram. The name coroutine derives from this symmetry rather than having a parent-child or caller-callee relationship between the two subprograms, the two subprograms appear more as equals - two subprograms swapping control back and forth as each executes, with neither clearly controlling the other.
fig-----
Implementation :- The resume instractions that transfer control between coroutines must have to specify the resumption of some particular activation of the coroutines. If there are multiple recursive activation's of a coroutine exists at a time.
The restriction over a co-routine is that at most one activation of given co-routine exists at a time.
A location is now need to be stored with a resume point, is reserved in the activation record to save the old ip value of the CIP. The return command used to save the value of ip i.e a co-routines is used to store the ip value for itself.
The resume instruction in co-routine involves two steps :->
- The current value of the CIP is saved in the resume point of the activation record for A.
- The ip value in the resume point location of B is fetched from B's activation record and assigned to the CIP to effect the transfer of control to the proper instruction in B.
- Java threads and Interrupts in Java programming language
- Abstract classes and Generic function in Java
- Callback functions in Java Programming language
- Constructors in programming language
- Static components and constants concept in programming language
- Data encapsulation in programming language.
- Java threads and Interrupts in Java programming language
1 comments:
This blog enabled me to achieve my learning objectives on this topic. Thanks for the efforts taken in sharing the thoughts with us.
ReplySpoken English Classes in Chennai
Spoken English Class in Chennai
Spoken English in Chennai
IELTS Training in Chennai
IELTS Chennai
Best English Speaking Classes in Mumbai
Spoken English Classes in Mumbai
IELTS Mumbai
IELTS Coaching in Anna Nagar
Spoken English Class in T Nagar
Post a Comment