Before discussing the difference between Exception handler and Event handler, let’s have a short introduction of the two.
Table of Contents
Exceptions are events that interrupt the flow of executions and make the program to execute further impossible. So, the exceptions need to be handled.
Exception situations can be detected and raised by either the program or runtime environment. Exceptions in the runtime environment are generally caused by the error situation that cannot be detected by the static program.
Exceptions can be either handleable or non-handleable. Handleable exceptions are class-based that are predefined in the system or can be custom-defined. They can be raised by the RAISE EXCEPTION or THROW statement and handled by TRY – CATCH – ENDTRY.
Non-handled exceptions create runtime error and the program terminates with a short dump.
Events are messages raised by the object when a condition is met. The events are caught by the event handler method that implements the logic to handle the event. These are used by objects or classes that trigger the event handler methods in other objects or classes. Any number of handler methods can be called when the event is triggered. The link between the trigger and the event handler method is decided at run-time. The event handler decides the event to which it wants to react.
Using RAISE EVENT statement, the events of a class can be triggered in the methods of the same class. A method of the same or different class is declared as event handler method for the event evt of class class using the addition FOR EVENT evt OF class.
Difference between Exception handler and Event handler
Now, let’s have a look at their difference.
|Exceptions are the error that occurs during the execution of a program that interrupts the normal flow of the control.||Events are the messages raised by an object which is raised when a condition is met|
|Exception handler is a unit of code that is executed after detection of an exception.||Event handler is a unit of code that is executed in response to an event.