What happens if the try block dosenot have any code in it?? is it legal and then is the catch block never accessable?? and wat abt the finally block?? u guies are the only ones i can come to ..need a way out.... cheers nik
u guies are the only ones i can come to ..need a way out....
Actually, we are not the only ones with the answer. The compiler is a much more reliable source than any "expert" since it has the final say of what can or cannot be done.
You cannot use any checked exception in a catch block if it is never thrown. so with the empty try block u can use catch with unchecked exceptions if exception is thrown or not but u can use checked exception only if it is thrown.
Checked exceptions r those checked by compiler unchecked exceptions r those which r not checked by compiler for eg arithmetic exception. arithmetic exceptions r considered programers problem n is not checked by compiler.a divide by zero for eg shud b checked by ur own code
Finaly will always execute irrespective of whether exception is thrown or not.
You cannot use any checked exception in a catch block if it is never thrown. so with the empty try block u can use catch with unchecked exceptions if exception is thrown or not but u can use checked exception only if it is thrown.
Huh? The try block is empty! Nothing will ever be thrown!
I wasn't questioning what Rajesh is saying about caught and uncaught exceptions. I was just wondering why we care about the catch block after an empty try block. In my very limited experience I can't think of a reason to use an empty try block and therefore a reason to care about the resulting catch block. But I'm more than willing to be enlightened if you can explain.
I agree that there is no reason to do it, but it's legal.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.