标签:out dex str 编译 info http get ima ==
Exception 分两种: 编译时异常和RuntimeException.
编译时异常必须要处理。
异常处理的五个关键字:throw,throws,try..catch,finally
1.使用throw抛出异常:
NullPointerException和 ArrayIndexOutOfBoundsException 都是运行时异常。
public static void main(String[] args) { int[] arr = null; int value = getElement(arr, 0); System.out.println(value); } public static int getElement(int[] arr,int index) { if(arr == null) { throw new NullPointerException("The array is null!"); } if(index<0||index>arr.length-1) { throw new ArrayIndexOutOfBoundsException("Index out of bounds:"+index); } int value = arr[index]; return value; } Exception in thread "main" java.lang.NullPointerException: The array is null! at exception.TestThrow.getElement(TestThrow.java:14) at exception.TestThrow.main(TestThrow.java:8)
标签:out dex str 编译 info http get ima ==
原文地址:https://www.cnblogs.com/Joyce-day-day-up/p/13947300.html