PLC Session 11

In this session we talked about Exception handling. As i said before, our group was initially presents subprogram but then we were ordered to rearrange our schedule. So, this session was presented by our group. This sessions are divided into a bunch of  topics

  • Introduction to Exception Handling
  • Exception Handling in C++
  • Introduction to Event Handling
  • Event Handling with Java
  • Event Handling in C#

So let’s talk about the topics that we are going to discuss. First topic is about  introduction Most computer hardware systems are capable of detecting certain run-time error conditions, such as floating-point overflow. There is a category of serious errors that are not detectable by hardware but can be detected by code generated by the compiler. For example, array subscript range errors are almost never detected by hardware, rbut they lead to serious errors that often are not noticed until later in the program execution. Accordingly, we define exception to be any unusual event, erroneous or not, that is detectable by either hardware or software and that may require special processing. The special processing that may be required when an exception is detected is called exception handling. This processing is done by a code unit or segment called an exception handler. An exception is raised when its associated event occurs. Next topic is about Exception Handling in C++. C++ uses a special construct that is introduced with the reserved word try for this purpose. A try construct includes a compound statement called the try clause and a list of exception handlers. The compound statement defines the scope of the following handlers. The general form of this construct is

try {
//** Code that might raise an exception
}
catch(formal parameter) {
//** A handler body
}
. . .
catch(formal parameter) {
//** A handler body
}

Each catch function is an exception handler. A catch function can have only a single formal parameter, which is similar to a formal parameter in a function definition in C++.After a handler has completed its execution, control flows to the first statement following the try construct an exception, using a throw without an expression, in which case that exception is propagated. Next topic is about Introduction to Event Handling. Event handling is similar to exception handling. In both cases, the handlers are implicitly called by the occurrence of something, either an exception or an event. While exceptions can be created either explicitly by user code or implicitly by hardware or a software interpreter, events are created by external actions, such as user interactions through a graphical user interface (GUI). An event is a notification that something specific has occurred, such as a mouse click on a graphical button. Strictly speaking, an event is an object that is implicitly created by the run-time system in response to a user action, at least in the context in which event handling is being discussed here. An event handler is a segment of code that is executed in response to the appearance of an event. Event handlers enable a program to be responsive to user actions. Common use of event handlers is to check for simple errors and omissions in the elements of a form, either when they are changed or when the form is submitted to the Web server for processing. Using event handling  on the browser to check the validity of form data saves the time of sending that data to the server, where their correctness then must be checked by a server-resident program or script before they can be processed. Let’s go to the next topics, we were talking about Event Handling with Java.

When a user interacts with a GUI component, for example by clicking a button, the component creates an event object and calls an event handler through an object called an event listener, passing the event object. The event handler provides the associated actions. GUI components are event generators; they generate events. In Java, events are connected to event handlers through event listeners. Event listeners are connected to event generators through event listener registration. Listener registration is done with a method of the class that implements the listener interface, as described later in this section. Only event listeners that are registered for a specific event are notified when that event occurs. The listener method that receives the message implements an event handler. To make the event-handling methods conform to a standard protocol, an interface is used. An interface prescribes standard method protocols but does not provide implementations of those methods.Event handling in C# is the last topic, Event handling in C#  is similar to that of Java. .NET provides two approaches to creating GUI’s in applications, the original Windows Forms and the more recent Windows Presentation Foundation. The latter is the more sophisticated and complex of the two. All C# event handlers have the same protocol: the return type is void and the two parameters are of types object and EventArgs. Neither of the parameters needs to be used for a simple situation. An event handler method can have any name.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *