OOP - Mod 5 - Error Handling, Graphical User Interface Development, Object Serialization,, Lecture notes of Programming Paradigms

Error Handling, Graphical User Interface Development, Object Serialization, and File Handling

Typology: Lecture notes

2020/2021

Available from 04/02/2022

gwen-hermo
gwen-hermo 🇵🇭

10 documents

1 / 32

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download OOP - Mod 5 - Error Handling, Graphical User Interface Development, Object Serialization, and more Lecture notes Programming Paradigms in PDF only on Docsity!

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.

➢ An exception handler is considered appropriate if the type of the exception object thrown matches the type that can be handled by the handler. ➢ Catch The Exception

  1. If the runtime system exhaustively searches all the methods on the call stack without finding an appropriate exception handler, as shown in the next figure, the runtime system (and, consequently, the program) terminates. TRY-CATCH BLOCK

Create an event (addActionListener)

Error Handling

SCHEDULE

Oral defense: 1v1 with Sir

Example: