ITeye博客

java之catch语句

yoyo08 · 2010-01-13 20:16 · Java · 编程语言 · Markdown

如下面代码:

 

public class Test
{
	public static void main(String[] args)
	{
		Test t = new Test();
		t.show();
	}
	
	public void show()
	{
		int a = 0;
		
		while(true)
		{
			try
			{
				if(a++ == 0)
					throw new MyException();
				
				System.out.println("No Exception");
				
			}catch(MyException e)
			{
				System.out.println("MyException");
			}catch(Exception e)
			{
				System.out.println("Exception");
			}finally
			{
				System.out.println("Finally");
				
				if(a == 2)
					break;
			}
		}
	}
}

class MyException extends Throwable
{
	private static final long serialVersionUID = -2022776205202627089L;
	
}

 

 

输出为:

 

MyException
Finally
No Exception
Finally

评论(0)

暂无评论。

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