Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Originally posted by Akhilesh Trivedi:
Because the compiler is intelligent enough to know that there are no chance that an IOException will be thrown in your try block.
catch(Exception t)
Originally posted by Nagarajulu Aerakoni:
Compiler gives error only for IOException here because it's a Checked Exception, where as Exception class is not a checked exception. For checked exceptions, compiler checks the possibility of error occurance in your code. if there's possibility and if you didn't catch such errors, it would also give error asking you to handle them.
But in this case, as your code does not deal with reading from/writing to files or any other standard input and output,it will find that you don't need to catch such an error.
You could also try including any unchecked exceptions like NullPointer Exception, ArrayIndexOutOfBoundsException in the above code; which are checked only at runtime, It doesn't give any error. But for IOException it does.
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
thanks & regards,<br />Anuj Bhatnagar
Originally posted by anuj bhatnagar:
the reason that your code does not compile is that to give IOException in a catch block you have to import the package java.io and it has nothing to do with checked or unchecked exceptions as explained by some of the raunchers.
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
try {
File obj = new File("Abc.txt");
obj.delete();
}
Thanks and Regards
Originally posted by Gitesh Ramchandani:
From the discussion above...
...
Please correct my understanding....
if (it)is not necessary to import java.io for catching an IOException.
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Originally posted by anuj bhatnagar:
the reason that your code does not compile is that to give IOException in a catch block you have to import the package java.io and it has nothing to do with checked or unchecked exceptions as explained by some of the raunchers.
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Originally posted by Gitesh Ramchandani:
Akhilesh,
What is to note in:
Is it different from catch(IOException t)?
Gitesh
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
SCJP-1.5<br />SCWCD-1.4
all events occur in real time
SCJP-1.5<br />SCWCD-1.4
We're being followed by intergalactic spies! Quick! Take this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|