Why runtime exception is unchecked exception?

前端 未结 5 1128
庸人自扰
庸人自扰 2020-12-10 11:19

Generally if any class extends Exception , it becomes checked exception. Runtime exception also extends Exception. Then how is it unchecked e

5条回答
  •  有刺的猬
    2020-12-10 11:52

    Run-time exception is called unchecked exception since it's not checked during compile time. Everything under throwable except ERROR and RuntimeException are checked exception. Adding Runtime exception in program will decrease the clarity of program.

    class Divide {
        public static void main(String [] args){
            int a = 10;
            int b = 0;
            int c = a/b; // This will throw run time exception due to unexpected value of b.
        }
    }
    

    Please read this link The Java™ Tutorials - Unchecked Exceptions — The Controversy

提交回复
热议问题