Checked exceptions are exceptions that must be encased within a try/catch block or the compiler will complain. For example...
public static void main(
String argv[])
{
RandomAccessFile r = new RandomAccessFile("iotest.txt","rw");
}
...would cause a compile time error. RandomAccessFile's constructor throws an IOException, and since IOException is not a subclass of RuntimeException, it is a checked exception. And since I'm not encasing it in a try/catch block, the compiler will complain.
The remedy is ...
public static void main(String argv[])
{
try {
RandomAccessFile r = new RandomAccessFile("iotest.txt","rw");
} catch (IOException e)
{
System.out.println("Checked Exception Caught");
}
}
On the other hand, the compiler doesn't check for runtime exceptions (unchecked exceptions). For example, since ArithmeticException is a subclass of RuntimeException, throwing it won't cause a compile time error.
For example...
public static void main(String argv[])
{
throw new ArithmeticException();
}
...would compile successful but give you an exception during runtime.
Hope that helped.
Jimmy Blakely,
Sun Certified
Java Programmer
Travis County Certified Defensive Driver
[This message has been edited by Jimmy Blakely (edited August 29, 2001).]