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);
    }
}

创建异常类对象

抛出异常

相关推荐
huaweichenai6 分钟前
spring boot实现base64上传
java·spring boot·后端
萧瑟余晖11 分钟前
Spring Web综合实战与性能调优详解
java·spring
点纭12 分钟前
spring ai1.0实战:ChatClient(2)
java·后端·spring
小马过河R16 分钟前
EdgeOne深度解析:从原理、适用场景到COS接入的技术逻辑
java·开发语言·前端·spring·cos
知守观17 分钟前
多模块工程没 install,跑起来的代码是上周的:Maven reactor 依赖解析踩坑
java·maven·intellij idea
java水泥工37 分钟前
什么是前端
java·vue·html5
Rain的Java大神之路1 小时前
Java 工程师做 AI,核心机会在「落地」而非「训练」
java·后端·ai编程
薛之谦_1 小时前
JAVA 多线程编程:从基础原理到实战应用
java·开发语言
LMT_Lanmantech1 小时前
Creo许可降本增效:不增购,也能让现有许可发挥更大价值
java·大数据·开发语言
Shaoshing2 小时前
Serializable
java