Avatar of gudii9
gudii9
Flag for United States of America

asked on 

When do we rethrow exception in catch block with different exception

Hi,

When do we rethrow exception in catch block with different exception?

Say


class ExceptionClass
{
public static void main(String[] args){
try {
System.out.println(9/0);
}
catch(ArithmeticException e) {
throw new NullPointerException();
}
}
}

I wonder whether we can do like above and in what situations we do like above?
please advise
JavaJava EE

Avatar of undefined
Last Comment
gurpsbassi

8/22/2022 - Mon