Wednesday, January 10, 2018

Session 11

Session 11
Saturday, 16 December 2017

This is the last session in 2017 year. This session talks about exception handling and event handling. 

In a language without exception handling:
When an exception occurs, control goes to the operating system, where a message is displayed and the program is terminated.

In a language with exception handling:
Programs are allowed to trap some exceptions, thereby providing the possibility of fixing the problem and continuing.

An exception is any unusual event, either erroneous or not, detectable by either hardware or software, that may require special processing. The special processing that may be required after detection of an exception is called exception handling. The exception handling code unit is called an exception handler.

Exception Handling Alternatives:
–Send an auxiliary parameter or use the return value to indicate the return status of a subprogram.
–Pass a label parameter to all subprograms (error return is to the passed label).
–Pass an exception handling subprogram to all subprograms.

Advantages of built-in Exception Handling :
•Error detection code is tedious to write and it clutters the program.
•Exception handling encourages programmers to consider many different possible errors.
•Exception propagation allows a high level of reuse of exception handling code.

Catch is the name of all handlers--it is an overloaded name, so the formal parameter of each must be unique.
Exceptions are all raised explicitly by the statement:
throw [expression];

An unhandled exception is propagated to the caller of the function in which it is raised. If no handler is found, default handler is called. After a handler completes its execution, control flows to the first statement after the last handler in the sequence of handlers of which it is an element.

An event is a notification that something specific has occurred, such as a mouse click on a graphical button. The event handler is a segment of code that is executed in response to an event.

That's all for this session. 

No comments:

Post a Comment