Any Checked exceptions can't be thrown without declaring a method or within a catch clause to handle it.Here we declared Exception is a parentclass and IOException and SQLException are subclasses of Exception.Then why the error "SQLException is not thrown in try block" at line1 is coming.I don't get that.Please help me.
You place the method call of code statements that may throw certain exception in the try block and then place catch block followed by that to handle that exception. If inside the try block the checked exception is not thrown, and you put catch block to handle that exception, compiler complaints that "are you sure you are doing write; there is nothing like SQLException in the try block, so for what you are handling that". Hence compilation error.
If you throw any checked exception in the catch block too, that exception must either be in the try catch block or declared to be thrown by the method. catch block placed to handle try block code never goes to handle exceptions generated in the catch block itself. That is what, as I see the matter of confusion to you. Is that right?