runtime exception in java
/* * Exception has a special subclass exception RunTimeException runtime exception * If an exception is thrown in the function content, the function can be declared without the declaration, and the compilation will pass * If the exception is declared on the function, the caller can not handle it, and the compilation will pass * The reason * is not declared on the function is because it does not need to be handled by the caller. * When this exception occurs, I hope that the program will stop, because when running, there is a situation where the operation cannot be continued. I hope that the code will be corrected after the program is stopped. * * When a custom exception occurs, if the exception occurs, the operation cannot continue * Let the custom exception inherit RunTimeException * * There are two types of exceptions: * 1. Exceptions detected at compile time * 2. Exceptions that are not detected at compile time (runtime exceptions, RunTimeException and its subclasses) * * * */ class Demo3{ int div(int a,int b){ if(b==0){ throw new ArithmeticException("Division by zero"); } return a/b; } } public class ExceptionDemo3 { public static void main(String args[]){ Demo3 d=new Demo3(); int x= d.div(4, 1); System.out.println("x="+x); System.out.println("over"); } }
----------------------By chick