代码拉取完成,页面将自动刷新
/**
* 功能:系统不允许输入负数
* 执行结果:
* 调用了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("我是日志操作");
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。