ITeye博客

Java之Exception与try语句

yoyo08 · 2010-02-01 18:21 · Java · 编程语言 · Markdown

代码如下:

 

public class Test1 
{
	public static void main(String[] args)
	{
		C c = new C();
		
		try
		{
			c.getExcC();
			
		}catch(Exception e)
		{
			System.out.println(e.getClass().getName());
		}
	}
}

class Aexception extends Exception
{
	
}

class Bexception extends Exception
{
	
}

class C
{
	public void getExcA() throws Aexception
	{
		throw new Aexception();
	}
	
	public void getExcB() throws Bexception
	{
		throw new Bexception();
	}
	
	public void getExcC() throws Exception
	{
		try
		{
			getExcA();
			
		}finally
		{
			getExcB();
		}
	}
}

 

 

输出为:

 

Bexception

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。