01-11-2012, 02:21 PM
Exceptions & Threads
Exceptions.ppt (Size: 49.5 KB / Downloads: 24)
Exceptions
You can compare Exceptions to Hardware Interrupts or Events
An Exception an important condition which needs immediate attention
Outside the normal operations of the program
Generally errors
We generate exceptions in several ways
Mathematical, Array Indexes, I/O Errors
Some Exceptions must be caught
If we might generate such an exception
We indicate this in the method definition
Exception Propagation
Finally block
Always executed (even without exceptions)
When an exception is generated
Appropriate handler
It is handled by the first appropriate handler and is not propagated.
No appropriate handler
It is propagated to the calling method.
Exception Extensions
Exceptions come in classes
The base class is called Exception
We can extend, and implement our own
class MyException extends Exception { … }
We can test for class membership in handlers
Polymorphism and instanceof
Need to test from most specific child to parent
An interesting field:
String msg
Exception Warnings
Some exceptions must be caught
If we use a method which may generate an exception we have two choices:
Handle the exception locally
Pass the buck
If we do so, we must indicate in our method declaration that we do this
int readTFint(TextField tf) throws ArrayIndex … {
Java & the Network
Java was designed with the network in mind
A network is a multi-processor computer
Some special needs
The ability to communicate
The ability to synchronize communications
These same features can be implemented on a single computer
Even one with a single processor
Background Processing
On a single computer
A significant amount of time is spent waiting for user input
This time can be put to better use
Consider Background Processes
Mail programs checking for mail
Word Processors checking spelling
Saving a file while you are working on it
Processes
A Process
A currently executing program on a computer
Program instructions, Memory (used and reserved), Other Resources (network & printer connections).
Creating a new process requires a significant amount of effort from the operating system
Security
Copies of memory & program information