誰かが私と同じ疑問に遭遇したかどうかはわかりません。なぜthrowを追加せずにメソッド本体内でthrownewRuntimeExceptionを使用すると、例外は発生しません。
①その理由は、RuntimeExceptionがプログラマのプログラミングエラーとしてプログラムによって認識され、外部にスローする必要がないためです。これは、範囲外の配列添え字、算術例外などに似ています。
②IOExceptionやClassNotFoundExcptionと同様に、手動でスローする必要があります
package Review;
/**
* @Author:CT
* @Date:2021/3/5
* @Description:Review
* @Version 1.0
*/
public class Review01 {
public static void main(String[] args) {
}
}
class Errors{
void show(){
throw new RuntimeException("运行出错");
}
}
class Errorss{
void show () throws Exception {
throw new Exception();
}
}