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

创建异常类对象

抛出异常

相关推荐
g***7270几秒前
Spring Framework 中文官方文档
java·后端·spring
2***6355几秒前
Spring 核心技术解析【纯干货版】- XII:Spring 数据访问模块 Spring-R2dbc 模块精讲
java·后端·spring
D***M9764 分钟前
SpringBoot 项目如何使用 pageHelper 做分页处理 (含两种依赖方式)
java
桦说编程4 分钟前
JDK1.8+ 中 ConcurrentHashMap#computeIfAbsent 源码解析与使用建议
java·后端·性能优化
2301_807288637 分钟前
MPRPC项目制作(第四天)
java·服务器·前端
TechMasterPlus17 分钟前
SpringBoot-RestController
java·spring boot·后端
m***667317 分钟前
Java实战:Spring Boot application.yml配置文件详解
java·网络·spring boot
棱角°18 分钟前
finally与return对于返回值的影响
java·finally·return
二川bro22 分钟前
内存泄漏检测:Python内存管理深度解析
java·开发语言·python
执笔论英雄32 分钟前
【RL】async_engine 远离
java·开发语言·网络