Re: Handling multiple exceptions in one exception handler block



Hi,

Adisht wrote:
Hi all,
I can anyone send me an example of how to catch 2 exceptions but handle
them together ?
Thanks,
Adi

Unfortunatly, (if the two exceptions do not have a supertype which the other exceptions do not have) this is not possible. You can only extract your code to a method:

try {
...
} catch(Exception1 e1) {
error(e1);
} catch(Excpetion2 e2) {
error(e2);
}

(Another possibility would be to catch the general class "Exception" and to do an instanceof-check, but this is not a good idea IMHO.)

Ciao,
Ingo

.



Relevant Pages