Why throw new RuntimeException does not need to add the throws keyword to the method body to throw this exception

I don’t know if anyone has encountered the same doubt as me, why use throw newRuntimeException inside the method body without adding throws and there will be no exception

① The reason is that RuntimeException is recognized by the program as a programming error of the programmer, and does not need to be thrown to the outside, similar to the array subscript out of bounds, arithmetic exception, etc.

② Similar to IOException and ClassNotFoundExcption, you need to manually throw

Insert picture description here

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();
    }
}

Guess you like

Origin blog.csdn.net/weixin_46351306/article/details/114408028