# 怎么在自己的ue4工程里边启用异常

**URL:** <https://forums.unrealengine.com/t/ue4/448035>\
**Category:** Community & Industry Discussion\
**Tags:** exception, unreal-engine, question\
**Created:** [April 29, 2019, 3:40am UTC](https://forums.unrealengine.com/t/ue4/448035 "2019-04-29T03:40:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ttaw](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ttaw](https://forums.unrealengine.com/u/ttaw)\
**Post date:** [April 29, 2019, 3:40am UTC](https://forums.unrealengine.com/t/ue4/448035/1 "2019-04-29T03:40:16Z")

</div>

我想在自己的一个ue4的C++项目exceptionTest中启用异常，发生如下情况：（UE4是用epiclauncher下载的4.21.2版本，VS2017）  
1.直接在源码里加上try catch块，结果编辑器下运行时发现不能捕获抛出的异常。并且打包时出现编译错误。网上搜索后尝试以下步骤  
2.在Proj.target.cs构造函数中加入this.bForceEnableExceptions=true，结果打包编译时出现编译错误，说是需要启用BuildEnvironment = TargetBuildEnvironment.Unique;  
3.启用该选项后打包编译时提示

 ![275462-捕获.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/1/4012783ad92c5e7b88d44fac077ad57ab15efbfc.png)

```
求解，怎么才能成功启用异常功能。

```

---

<div class="post-metadata">

**Author:** ![ttaw](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ttaw](https://forums.unrealengine.com/u/ttaw)\
**Post date:** [May 3, 2019, 2:47am UTC](https://forums.unrealengine.com/t/ue4/448035/2 "2019-05-03T02:47:50Z")

</div>

解决了，要启用异常只需要在Build.cs里增加bEnableExceptions = true;然后使用try catch就行了。但是这样无法捕获AccessViolation之类的SEH异常，SEH异常需要使用\_\_try \_\_except的vc扩展才能起作用，而且这种可以不设置bEnableExceptions=true。

---

<div class="post-metadata">

**Author:** ![NewAphid2817](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NewAphid2817](https://forums.unrealengine.com/u/NewAphid2817)\
**Post date:** [February 7, 2026, 2:22am UTC](https://forums.unrealengine.com/t/ue4/448035/4 "2026-02-07T02:22:53Z")

</div>

SEH异常需要使用\_\_try \_\_except,但是这个，异常捕获，里面变量都需要全局变量才行，不能使用局部变量，xx
