Mod 5
Error Handling, Graphical User Interface Development,
Object Serialization, and File Handling
Exception
➢ "exceptional event"
➢ An event, which occurs during the execution of a program that disrupts the
normal flow of the program's instructions
1. When an error occurs within a method, the method creates an object and hands it off to
the runtime system.
• Exception Object - contains information about the error, including its
type and the state of the program when the error occurred.
• Throwing An Exception - creating an exception object and handing it to
the runtime system
2. After a method throws an exception, the runtime system attempts to find something to
handle it.
• The set of possible "somethings" to handle the exception is the ordered
list of methods that had been called to get to the method where the error
occurred.
• Call Stack - list of methods
3. The runtime system searches the call stack for a method that contains a block of code that
can handle the exception.
• Exception Handler - contains a block of code that can handle the
exception.
4. The search begins with the method in which the error occurred and proceeds through the
call stack in the reverse order in which the methods were called.
5. When an appropriate handler is found, the runtime system passes the exception to the
handler.