exceptiondemo6.java
来自「JAVA程序设计课程中各章节的程序实例。」· Java 代码 · 共 69 行
JAVA
69 行
/**
*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 + =
减小字号Ctrl + -
显示快捷键?