|NO.Z.00065|——————————|BigDataEnd|——|Java&集合类库.V01|——|Java.v01|异常机制.v01|异常机制|概念|分类结构|

一、[异常机制基本概念]——[异常机制的分类和结构]
### --- 基本概念

——>        异常就是"不正常"的含义,在Java语言中主要指程序执行中发生的不正常情况。
——>        java.lang.Throwable类是Java语言中错误(Error)和异常(Exception)的超类。
——>        其中Error类主要用于描述Java虚拟机无法解决的严重错误,
——>        通常无法编码解决,如:JVM挂掉了等。
——>        其中Exception类主要用于描述因编程错误或偶然外在因素导致的轻微错误,
——>        通常可以编码解决,如:0作为除数等。
二、异常的分类
### --- 异常的分类

——>    java.lang.Exception类是所有异常的超类,主要分为以下两种:
——>        RuntimeException - 运行时异常,也叫作非检测性异常
——>        IOException和其它异常 - 其它异常,也叫作检测性异常,
### --- 所谓检测性异常就是指在编译阶段都能被编译器检测出来的异常。

——>    其中RuntimeException类的主要子类:
——>        ArithmeticException类 - 算术异常
——>        ArrayIndexOutOfBoundsException类 - 数组下标越界异常
——>        NullPointerException - 空指针异常
——>        ClassCastException - 类型转换异常
——>        NumberFormatException - 数字格式异常
### --- 注意:

——>        当程序执行过程中发生异常但又没有手动处理时,则由Java虚拟机采用默认方式处理异常,
——>        而默认处理方式就是:打印异常的名称、异常发生的原因、异常发生的位置以及终止程序。
三、异常的框架结构
四、编程代码
package com.yanqi.task16;

public class ExceptionTest {

    public static void main(String[] args) {

        // 1.见识一下非检测性异常  运行时异常
        System.out.println(5 / 0); // 编译ok,运行阶段会发生算术异常  下面的代码不会执行

        // 2.检测性异常
        //Thread.sleep(1000); // 编译错误  不处理就无法到运行阶段

        System.out.println("程序正常结束了!");
    }
}
五、编译打印
D:\JAVA\jdk-11.0.2\bin\java.exe "-javaagent:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=58512:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath E:\NO.Z.10000——javaproject\NO.H.00001.javase\javase\out\production\javase com.yanqi.task16.ExceptionTest
Exception in thread "main" java.lang.ArithmeticException: / by zero
    at com.yanqi.task16.ExceptionTest.main(ExceptionTest.java:8)

Process finished with exit code 1

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(25)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示