---
title: "Java之Exception与try语句"
author: "yoyo08"
date: "2010-02-01T18:21:51Z"
tags: []
categories: ["编程语言"]
slug: "java-exception-try"
draft: false
lastmod: "2010-02-01T18:21:51Z"
id: 585244
url: "https://yoyo08.iteye.com/blog/585244"
---

代码如下：

 

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