📄 exception4.java
字号:
//抛出异常的方法
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -