异常的使用概述
异常及时Java程序在运行的过程中出行的错误
异常分类
JVM是如何处理异常的
main方法遇到这种问题有两种处理异常的方式 a:自己将问题处理,然后运行 b:没有针对处理方式,就会交给main方法的JVM去处理 c:JVM里面有一个默认的异常处理机制,将异常的名称,信息打印在控制台,并停止程序运行。
try抛出异常的三种方式
try...catch
try...finally
try...catch...finally
public class Demo2_Exception {
public static void main(String[] args) {
// demo();
int a=10;
int b=0;
int[] arr = {11, 22, 33, 44, 55};
try {
int c=a/b;
arr=null;
System.out.println(arr[10]);
System.out.println(c);
//JDK7出现的抛出异常方法,只要出现其中一个就可以抛出异常,为发生错误
}catch(ArithmeticException |ArrayIndexOutOfBoundsException e){