---
title: "java之catch语句"
author: "yoyo08"
date: "2010-01-13T20:16:50Z"
tags: []
categories: ["编程语言"]
slug: "java-catch"
draft: false
lastmod: "2010-01-13T20:16:50Z"
id: 569553
url: "https://yoyo08.iteye.com/blog/569553"
---

如下面代码：

 

```
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
```