在Java中,重新抛出异常是什么意思?

在Java中,重新抛出异常是什么意思?

当异常缓存在 catch 块中时,您可以使用 throw 关键字(用于抛出异常对象)重新抛出异常。

重新抛出异常时,您可以抛出与未调整的情况相同的异常 -

try { int result = (arr[a])/(arr[b]); System.out.println("Result of "+arr[a]+"/"+arr[b]+": "+result); } catch(ArithmeticException e) { throw e; }登录后复制

try { int result = (arr[a])/(arr[b]); System.out.println("Result of "+arr[a]+"/"+arr[b]+": "+result); } catch(ArrayIndexOutOfBoundsException e) { throw new IndexOutOfBoundsException(); }登录后复制