throwsexception.java

来自「Java语言是目前最流行」· Java 代码 · 共 34 行

JAVA
34
字号
//生声明异常
class ThrowException
{
	public static void main(String[] aa)
	{
		try
		{
			Method(0);
			Method(1);
		}
		catch(NumberFormatException e)
		{ System.out.println("\t捕获异常:"+e); }  
		catch(ArrayIndexOutOfBoundsException e)
		{ System.out.println("\t捕获异常:"+e); }
		finally
		{ System.out.println("\t finally块总是被执行."); }			
	}	

static void Method(int i) throws ArithmeticException,NumberFormatException
{
	System.out.println("\t调用方法method("+i+")");
	if (i==10)
	{
		System.out.println("\t没有异常");
		return;	
	}	
	else if(i==1)
	{
		String str = "abc";
		int k;
		k = Integer.parseInt(str);	
	}
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?