📄 try7.java.bak
字号:
class OverflowException extends Exception //自定义异常类
{
public void printMsg()
{
System.out.println("exception: "+this.getMessage());
this.printStackTrace();
System.exit(0);
}
}
public class Try7
{
public void calc(int k) throws OverflowException //抛出异常
{
int y=1,i=1;
System.out.print(k+"!=");
for (i=1;i<=k;i++)
{
if(y>Integer.MAX_VALUE/i)
throw new OverflowException();
else
y = y * i;
}
System.out.println(y);
}
public void run(int k) //捕获并处理异常
{
try
{
calc(k);
}
catch(OverflowException e)
{
e.printMsg();
}
}
public static void main (String args[])
{
Try7 a = new Try7();
for (int i=1;i<20;i++)
a.run(i);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -