File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error handling

 
Artemesia Lakener
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I have --

try {

code_part_1;
try {
code_part_2;
} catch (IOException e) {
handle it;
}
code_part_3;
} catch(IOException e) {
handle it in another way differently;
}


Is it ok to do this ? what I really want to do is --
if code_part_2 causes IOException I want to deal with it specifically; if code_1 and code_3 causes IOException, I want to handle it in another way. Does my code suit my need ?
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Artemesia,

You can't catch the same exception twice in a row: that's just not allowed. However, you could catch subclasses of the same exception twice: say first catch a FileNotfoundException, then a FileException. IMO, you should only do this if you're going to be taking different actions based on the type of exception: otherwise, you probably just want to catch the base class.

Make sense?
M
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic