aspose file tools*
The moose likes Beginning Java and the fly likes What if there is too much exceptions to handle? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What if there is too much exceptions to handle?" Watch "What if there is too much exceptions to handle?" New topic
Author

What if there is too much exceptions to handle?

Hui Ge
Greenhorn

Joined: Mar 11, 2005
Posts: 25
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

Joined: Jun 30, 2004
Posts: 186
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.


Drinking more tea is the key...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What if there is too much exceptions to handle?