s-day05--异常的结构以及异常的分类
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
package com.inmind.exception01;
|
||||||
|
/*
|
||||||
|
异常:程序运行时,会产生的一些问题或者错误。
|
||||||
|
|
||||||
|
在java中有一个类专门来表示错误和异常,Throwable
|
||||||
|
Throwable类是Java语言中所有错误和异常的超类。
|
||||||
|
Throwable分类:
|
||||||
|
1.错误 Error,表示程序发生不可挽救的错误。
|
||||||
|
2.异常Exception,表示程序发生轻微问题,可以处理。
|
||||||
|
|
||||||
|
内存溢出:申请了超出了原本内存空间(16G)的更大的空间(20G)
|
||||||
|
内存泄漏:一个再也不需要使用的对象,占用了一块内存区域后,没有被释放,这就是泄漏
|
||||||
|
*/
|
||||||
|
public class Demo01 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//空指针异常
|
||||||
|
/*int[] arr = null;
|
||||||
|
System.out.println(arr[0]);*/
|
||||||
|
//错误:OutOfMemoryError内存溢出错误
|
||||||
|
/*int[] arr1 = new int[10000*10000*100];
|
||||||
|
int[] arr2 = new int[10000*10000*100];
|
||||||
|
int[] arr3 = new int[10000*10000*100];
|
||||||
|
int[] arr4 = new int[10000*10000*100];
|
||||||
|
int[] arr5 = new int[10000*10000*100];*/
|
||||||
|
|
||||||
|
System.out.println("程序结束");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user