Ai
1 Star 0 Fork 0

spring299792/JAVA学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
exception.java 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
spring299792 提交于 2020-03-05 16:54 +08:00 . 自带方法使用
/**
* 功能:系统不允许输入负数
* 执行结果:
* 调用了method
* method正常返回
* 调用了method
* 系统不允许输入负数:-1
* 我是日志操作
*/
class myException extends Exception{
public int num;
myException(int a){
num = a;
}
public String outshow(){
return "系统不允许输入负数:"+num;
}
}
class exception {
static void method(int a) throws myException{// throws IOException如要使用io的话,必须要使用io的异常。
System.out.println("调用了method");
if(a < 0){
throw new myException(a);
}
System.out.println("method正常返回");
}
public static void main(String[] args){
char in;
try {
method(0);
method(-1);
method(1);
}
catch (myException e){
System.out.println(e.outshow());
}
finally {
System.out.println("我是日志操作");
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/spring299792/java_study.git
git@gitee.com:spring299792/java_study.git
spring299792
java_study
JAVA学习
master

搜索帮助