day28 异常

to{}catch{}

try{}catch{}的流传输

复制代码
try {
    fis = new FileInputStream("file-APP\\fos.txt");
    fos = new FileOutputStream("fos.txt");
    int a ;
    while ((a= fis.read())!= -1){
        fos.write(a);
    }
    System.out.println(a);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        if (fis != null) {
            fis.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

try(){}catch{}的流传输 省略close()

try{}catch{}finally{}


finalize()方法*

Objects的equals()方法*


抛异常

自己怎么创建异常 抛异常

创建异常类 重载所有构造方法

复制代码
class StudentAgeIllegalException extends Exception {
    public StudentAgeIllegalException() {
    }

    public StudentAgeIllegalException(String message) {
        super(message);
    }

    public StudentAgeIllegalException(String message, Throwable cause) {
        super(message, cause);
    }

    public StudentAgeIllegalException(Throwable cause) {
        super(cause);
    }

    public StudentAgeIllegalException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }
}

创建异常类对象

抛出异常

相关推荐
code小毛孩1 小时前
如何简单的并且又能大幅度降低任务队列的锁粒度、提高吞吐量?
java·jvm·数据库
你不是我我1 小时前
【Java开发日记】请介绍类加载过程,什么是双亲委派模型?
java·开发语言
牢七1 小时前
java10
java
阿挥的编程日记1 小时前
基于SpringBoot的高校(学生综合)服务平台的设计与实现
java·spring boot·后端·spring·mybatis
小霞在敲代码1 小时前
ArrayList - 数据结构 - 数组
java·索引
一个小白开发3 小时前
ip获取城市省份信息
java·tcp/ip
豆沙沙包?3 小时前
2025年--Lc170--H289. 生命游戏(矩阵)--Java版
java·游戏·矩阵
冬夜戏雪3 小时前
[学习日记][springboot 1-7][leetcode 6道]
java·开发语言·学习
讓丄帝愛伱3 小时前
idea 中 mapper.xml黄线警告怎么去掉
java·intellij-idea
桦说编程3 小时前
线程池拒绝策略避坑:谨慎使用抛弃策略,可能导致系统卡死
java·后端