This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am a little bit confused about exception handling. I have some question about it and I would very appreciate if you can help me!
1. If I have a method, that throws more than one exception. What is the right way to handle these exceptions? For example: For Naming.lookup(�) there are three defined exception. What is the correct way to handle it? Catch every exception:
or catch only the main Exception:
2. Are there are some books, links with something like "best practice". Could you recommend me?
there is a book that every Java developer should have which is "Effective Java" by Joshua Bloch. This also handles the topic of handling exceptions appropriately. In this case my guess would be that the topic "throw exceptions appropriate to the abstraction" would be a good start.
However, you need to regard the method where you handle these exceptions in the context of your application and decide which of the recommendations fits you best.
"The UrlyBird catches the certificate. And he's gonna FlyByNight"<br /> <br />SCJP 1.2/5.0, SCJD, SCBCD, SCWCD, SCEA
In geneal is bad to catch the Exception exception because the Exception is the super(parent) class for all the exceptions runtime or not so you catch all and you can not make a distionction between the them. But sometimes the runtime exceptions means a promming(logic) error and it better to let them to occur from beginig.