This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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...
 
jQuery in Action, 2nd edition
 
subject: What if there is too much exceptions to handle?
 
Similar Threads
How to read file line by line and word by word?
Exception handling
Exception handling
please tell me.......................
about nested try catch