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

创建异常类对象

抛出异常

相关推荐
砍材农夫4 分钟前
物联网 基于netty构建mqtt服务协议支持
java·物联网·struts·netty
凤凰院凶涛QAQ9 分钟前
《C++转Java快速入手系列》String篇:在C++里拼字符串像搬砖,在Java里拼字符串像玩乐高 —— 还是带垃圾回收的那种。
java·开发语言·c++
会编程的吕洞宾9 分钟前
Spring_Boot_3_3_的___Transactional__
java·后端·spring
轻刀快马14 分钟前
讲明白Lambda 表达式的进化史
java·开发语言
那个失眠的夜16 分钟前
SpringBoot
java·开发语言·spring boot·spring·mvc·mybatis
多敲代码防脱发36 分钟前
Spring进阶(Bean的生命周期与Bean的后处理器)
java·服务器·开发语言·spring boot·spring·servlet
RingWu43 分钟前
高并发三板斧-缓存:命中率、一致性、治理
java·spring·缓存
流年如夢1 小时前
类和对象(上)
android·java·开发语言
huipeng9261 小时前
基于SpringCloud的博客系统
java·运维·后端·spring·spring cloud·微服务
@SmartSi1 小时前
AgentScope Java 入门:搭建第一个 ReAct 智能体
java·agentscope