我遇到了一个问题,不理解异常抛出时会发生什么。
抛出的异常会被如何处理?是什么处理它以确保程序不崩溃?
例如,在这篇教程中的示例中,谁将处理抛出的ArithmeticException
?
static int remainder(int dividend, int divisor)
throws DivideByZeroException {
try {
return dividend % divisor;
}
catch (ArithmeticException e) {
throw new DivideByZeroException();
}
}