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

创建异常类对象

抛出异常

相关推荐
踢球的打工仔6 分钟前
PHP面向对象(5)
android·java·php
Rover.x8 分钟前
错误:找不到或无法加载主类 @C:\Users\AppData\Local\Temp\idea_arg_file223456232
java·ide·intellij-idea
4***172710 分钟前
使用 java -jar 命令启动 Spring Boot 应用时,指定特定的配置文件的几种实现方式
java·spring boot·jar
CoderYanger26 分钟前
优选算法-字符串:63.二进制求和
java·开发语言·算法·leetcode·职场和发展·1024程序员节
3***312127 分钟前
java进阶1——JVM
java·开发语言·jvm
FeiHuo5651540 分钟前
微信个人号开发中如何高效实现API二次开发
java·开发语言·python·微信
源码技术栈1 小时前
什么是云门诊系统、云诊所系统?
java·vue.js·spring boot·源码·门诊·云门诊
Coder-coco1 小时前
游戏助手|游戏攻略|基于SprinBoot+vue的游戏攻略系统小程序(源码+数据库+文档)
java·vue.js·spring boot·游戏·小程序·论文·游戏助手
Qiuner1 小时前
Spring Boot 机制二:配置属性绑定 Binder 源码解析(ConfigurationProperties 全链路)
java·spring boot·后端·spring·binder
D***77652 小时前
适用于IntelliJ IDEA 2024.1.2部署Tomcat的完整方法,以及笔者踩的坑,避免高血压,保姆级教程
java·tomcat·intellij-idea