📄 exloss.java
字号:
public class ExLoss{
public int methodA(int money)throws SpecialException{
if(--money<=0) throw new SpecialException("Out of money");
return money;
}
public int methodB(int money)throws Exception{
try{
return methodA(money); //可能抛出异常
}catch(SpecialException e){
throw new Exception("Wrong");
}finally{
return 100;
}
}
public static void main(String args[]){
try{
System.out.println(new ExLoss().methodB(1)); //打印100
System.out.println("No Exception");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
/****************************************************
* 作者:孙卫琴 *
* 来源:<<Java面向对象编程>> *
* 技术支持网址:www.javathinker.org *
***************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -