In the above code am using the NumberFormatException to catch the exception. But, i can also use the super class Exception also in the catch clause, thats okay. Is there reason or advantage of using the particular class say (NumberFormatException) instead of super class (Exception) in the catch clause. Is there any reasons like saving the compilation time.
There is an diff' between wild card import and ordinary import.
Here 1st type is wild card import, In this the compiler will import all the classes in that package. But am using only ArrayList in my program. So there is waste of compilation time here. Its is not efficient to use wild card import statement.
Like this any reason is there while declaring exception class in catch clause??
Coming to your question: No the intention of catching a specific type of exception is simple: You want to perform a specific action *only* when that exception occurs. Its the same thing as saying "dude there is *something* wrong in your input" as opposed to saying "dude you need to enter a number here and not your name" !! You can only do this when either you catch NumberFormatException or check instance of the Exception caught (This will make people looking at the code crazy and put a price on your head!) and then take different actions. [ February 26, 2008: Message edited by: Nitesh Kant ]