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

What if there is too much exceptions to handle?

 
Hui Ge
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it advisable to create a general exception class with an exceptionType String for example to differentiate between the exception types?

Instead of this:

try {
//run some codes
}catch(AException ae) {

}catch(BException be) {

}catch(CException ce) {

}

We can do this:

try {
//run some codes
}catch(GeneralException ge) {
System.out.println(ge.getExceptionType());
}
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really, exceptions types are there to be handled specifically i.e.

catch(A_SpecificException e){}
catch(Another_specific_exception e){}
catch(Exception e) {}

If you are simply trying to reduce the number of catches because there are too many exception to handle, consider sub-classing or restricting what each try block does.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic