• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

What if there is too much exceptions to handle?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Do Re Mi Fa So La Tiny Ad
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic