Think of it this way....
You have some kind of animal in your garage hiding out that you dont see but you know he is in there.
If you want to catch him, you have to set a trap. If you don't set a trap you definitely WILL not catch him.
Think of the
try {
}
catch {
}
blocks as "setting the trap".
It doesn't mean that you WILL DEFINITELY get one.....BUT.... if you do anything in the "try block" that DOES generate one you will catch it, presuming your catch block is properly designed.
And, in the case of
Java, the compiler will remind you that there is something living in your garage that you had BETTER set a trap for. So if you DON'T set the trap, it will remind you!
-----
--------
Oh....and the traps can come in different sizes (hierarchical types) that you can "layer"..... thus
this is a poor example of inheritance but the idea to get is that your "traps" ( catch block conditions ) should get wider as you go. Put the "more specific" exception types higher and the "less specific/more general" exception types later in the chain. catching something higher up the inheritance chain (in the superclass direction) will certainly catch more subtypes but then you might have to figure out for yourself what type it is. Java allows you to let it do the "filtering" work for you.
[ July 25, 2007: Message edited by: Bob Ruth ]