exception4.java
来自「课本异常处理实例。各种异常处理」· Java 代码 · 共 26 行
JAVA
26 行
//抛出异常的方法
public class Exception4
{
public static int Sum() throws NegativeArraySizeException
{
int s = 0;
int x[] = new int[-4];
for (int i=0; i<4; i++)
{
x[i]=i;
s = s + x[i];
}
return s;
}
public static void main(String args[])
{
try
{
System.out.println(Sum());
}
catch (NegativeArraySizeException e)
{
System.out.println("异常信息:"+e.toString());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?