---
title: "C++ 接异常时的注意"
author: "chenqi210"
date: "2011-06-24T23:55:45Z"
tags: ["C++"]
categories: ["编程语言"]
slug: "c"
draft: false
lastmod: "2011-07-08T14:20:59Z"
id: 1104434
url: "https://chenqi210.iteye.com/blog/1104434"
---

```
void test1()
{
	try
	{
		try
		{
			throw runtime_error("asdfasdf");
		}
		catch(std::exception &e)
		{
			throw e;
		}
	}
	catch(std::runtime_error &e)
	{	
		throw e;
	}
	catch(std::exception &e)
	{
		cout<<e.what()<<endl;
	}
}
```

 

这段代码都有输出：

 在vc2010里输出 仍然是 asdfasdf

但是mingw4.5.2里输出则是std::exception

 

当runtime\_error 被扔出来的时候，exception& e接住了,但是 e再抛出的时候，因为已经是exception的异常了，所以只能被第三个catch接住.