📄 exceptiondemo6.java
字号:
/**
*A demonstration of some Built-in exceptions
*pay more attention!
*2004.12.25. xhcprince
*/
class exceptionDemo6
{
public static void func()
{
for(int i=0; i<3; ++i)
{
int k;
try
{
System.out.println("Exception handling");
try
{
switch(i)
{
case 0:
int zero = 0;
k = 6/0;
break;
case 1:
int[] array = new int[2];
k = array[9];
break;
case 2:
char ch = "Hello".charAt(66);
break;
}
}
catch(ArithmeticException e)
{
System.out.println("Arithmetic Exception: " + e.getMessage());
}
catch(IndexOutOfBoundsException e)
{
System.out.println("Index Out Of Bounds Exception: " + e.getMessage());
throw e;
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array Index Out Of Bounds Exception: " + e.getMessage());
}
}
}
public static void main(String args[])
{
try
{
func();
}
catch(RuntimeException e)
{
System.out.println("Main() Runtime Exception: " + e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -