Adisht said:
Hi all,
I can anyone send me an example of how to catch 2 exceptions but handle
them together ?
Thanks,
Adi
hi,
I had to catch two exceptions, which did not extend the same class, and
log the details of these exceptions. But I did not want to catch all
Exceptions or Throwables that could possibly occur so I did the
following:
1.) Wrapped the code and caught the possible exceptions I want handled
try{
// logic that could throw exception
} catch (Exception1 e1){
handleExceptionWithCommonCode(e1);
} catch (Exception2 e2){
handleExceptionWithCommonCode(e2);
}
2.) Then wrote a private method to handle these exceptions
private void handleExceptionWithCommonCode(Exception e){
// process the exception i.e. log it
}
Am also curious to see if anyone has a neater solution.
Chris