?? try7.java
字號(hào):
class OverflowException extends Exception //自定義異常類(lèi)
{
public void printMsg()
{
System.out.println("exception: "+this.getMessage());
this.printStackTrace();
System.exit(0);
}
}
public class Try7
{
public void calc(byte k) throws OverflowException //拋出異常
{
byte y=1,i=1;
System.out.print(k+"!=");
for (i=1;i<=k;i++)
{
if(y>Byte.MAX_VALUE/i)
throw new OverflowException();
else
y = (byte)(y * i);
}
System.out.println(y);
}
public void run(byte k) //捕獲并處理異常
{
try
{
calc(k);
}
catch(OverflowException e)
{
e.printMsg();
}
}
public static void main (String args[])
{
Try7 a = new Try7();
for (byte i=1;i<10;i++)
a.run(i);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -