Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API
In order to develop a clear and consistent strategy for exception handling, examine these questions that continually plague Java developers:
When trying to design APIs and applications that can cross system boundaries or be implemented by third parties, these issues only exacerbate.
Let's delve deeper into the various aspects of exceptions.
Exceptions are of two types:
Compiler-enforced (checked) exceptions are instances of the Exception class or one of its subclasses -- excluding the RuntimeException branch. The compiler expects all checked exceptions to be appropriately handled. Checked exceptions must be declared in the throws clause of the method throwing them -- assuming, of course, they're not being caught within that
same method. The calling method must take care of these exceptions by either catching or declaring them in its throws clause. Thus, making an exception checked
forces the programmer to pay heed to the possibility of it being thrown. An example of a checked exception is java.io.IOException. As the name suggests, it throws whenever an input/output operation is abnormally terminated. Examine the following code:
try
{
BufferedReader br = new BufferedReader(new FileReader("MyFile.txt"));
String line = br.readLine();
}
catch(FileNotFoundException fnfe)
{
System.out.println("File MyFile.txt not found.");
}
catch(IOException ioe)
{
System.out.println("Unable to read from MyFile.txt");
}
The constructor of FileReader throws a FileNotFoundException -- a subclass of IOException -- if the said file is not found. Otherwise, if the file exists but for some reason the readLine() method can't read from it, FileReader throws an IOException.
Runtime (unchecked) exceptions are instances of the RuntimeException class or one of its subclasses. You need not declare unchecked exceptions in the throws clause of the throwing method. Also,
the calling method doesn't have to handle them -- although it may. Unchecked exceptions usually throw only for problems arising
in the Java Virtual Machine (VM) environment. As such, programmers should refrain from throwing these, as it is more convenient
for the Java VM to manage this part.
Free Download - 5 Minute Product Review. When slow equals Off: Manage the complexity of Web applications - Symphoniq
![]()
Free Download - 5 Minute Product Review. Realize the benefits of real user monitoring in less than an hour. - Symphoniq