Class RuntimeException
- Java.lang.Object
- Java.lang.Throwable
- Java.lang.Exception
- Java.lang.RuntimeException
- ArithmeticException
- Indexoutofboundsexception
- ......
Public classExceptiontest { Public Static voidMain (string[] args) {Divdemo dd=NewDivdemo (); intResultd; Resultd= Dd.div (10, 0); System.out.println ("Resultd ' value is:" +Resultd); System.out.println ("Over!"); }}/**-----------------Class arithmeticexception * java.lang.Object * java.lang.Throwable * java.lang.Excepti On * java.lang.RuntimeException * java.lang.ArithmeticException **/ classdivdemo{/**runtimeexception features * runtimeexception <--ArithmeticException * Method internal to JVM throwing <RuntimeException> exceptions * Method name can not add throws Xxxexception, you can not declare this function to throw an exception, do not let the caller handle, is to let the program stop. * * The programmer who calls the method cannot handle the exception, only changes to the program to conform to the legitimacy of the incoming parameter. * */ Public intDivintAintb) { if(b = = 0 ){ Throw NewArithmeticException ("----by zero!"); } returnA/C; }}
: Console:
--------------------------------------------------------------------------
Get
Java Basics-Exception-runtimeexception