Re: Handling multiple exceptions in one exception handler block
- From: "Chris Brat" <chrisBrat@xxxxxxxxx>
- Date: 17 Jul 2006 02:40:19 -0700
Adisht wrote:
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
.
- References:
- Prev by Date: Re: Aside from googling....
- Next by Date: Re: Handling multiple exceptions in one exception handler block
- Previous by thread: Re: Handling multiple exceptions in one exception handler block
- Next by thread: Thank you all !! -> Re: Handling multiple exceptions in one exception handler block
- Index(es):
Relevant Pages
|