# How can I enable unwind semantics for C++-style exceptions?

**URL:** <https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 4, 2014, 4:52am UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934 "2014-06-04T04:52:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![adelesky\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adelesky\_1](https://forums.unrealengine.com/u/adelesky_1)\
**Post date:** [June 4, 2014, 4:52am UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/1 "2014-06-04T04:52:29Z")

</div>

I am having an issue with my project compiling. I am integrating the SqlApi++ library to allow my project to post gameplay metrics to a MySQL server, but my project fails to compile when I build it for Development mode. While it works when built for Development-Editor, it throws a C4530 warning when building for Development in version 4.0, 4.1, and 4.1.1 of the engine.

The compiler complains about me using a try/catch statement to wrap my calls to the server. Specifically, it errors out on the start of the try/catch block itself, such that using

`try {} catch (SAException&) {}`

will cause the compilation to fail. The error returned is:

` warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc`

The odd thing is, though, I know another team is using the exact same library, but have never received this error nor had to manually specify the /EHsc flag when compiling their project (at least to my knowledge). How can I set this flag when building my project?

Any help on this matter would be greatly appreciated. Thanks!

–

---

<div class="post-metadata">

**Author:** ![RCL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RCL](https://forums.unrealengine.com/u/RCL)\
**Post date:** [June 4, 2014, 2:39pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/2 "2014-06-04T14:39:00Z")

</div>

We normally don’t use exceptions, but you can enable them by setting bForceEnableExceptions to true in BuildConfigratuion.xml (locate that file in Solution)

---

<div class="post-metadata">

**Author:** ![adelesky\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adelesky\_1](https://forums.unrealengine.com/u/adelesky_1)\
**Post date:** [June 4, 2014, 8:26pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/3 "2014-06-04T20:26:41Z")

</div>

Unfortunately, that option doesn’t seem to be supported in 4.1.1. I added it to the BuildConfiguration, and the BuilderTool broke.

---

<div class="post-metadata">

**Author:** ![RCL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RCL](https://forums.unrealengine.com/u/RCL)\
**Post date:** [June 5, 2014, 7:06pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/4 "2014-06-05T19:06:34Z")

</div>

Well, you can always hack VCToolChain.cs in UnrealBuildTool to add /EHsc (look up the code where it gets added) 🙂 This is the dirtiest solution possible though (which will work though), I suggest that you first try to sort out the problem why you could not do that through BuildConfiguration.

---

<div class="post-metadata">

**Author:** ![adelesky\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adelesky\_1](https://forums.unrealengine.com/u/adelesky_1)\
**Post date:** [June 5, 2014, 9:03pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/5 "2014-06-05T21:03:39Z")

</div>

Bleh. Didn’t mean to delete that.

Anyway, it doesn’t seem like bForceEnableExceptions is a member in the BuildConfiguration.cs file, and editing the BuildConfiguration.xml file to

`
<Configuration>   
<BuildConfiguration>
<bForceEnableExceptions>True</bForceEnableExceptions>
<BuildConfiguration>
`

`<Configuration>
`

causes the UBT to break with the following error:

`Unhandled Exception: UnrealBuildTool.BuildException: ERROR: BuildConfiguration Loading: field ‘bForceEnableExceptions’ doesn’t exist or is either non-public or non-static.`

---

<div class="post-metadata">

**Author:** ![RCL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RCL](https://forums.unrealengine.com/u/RCL)\
**Post date:** [June 5, 2014, 10:00pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/6 "2014-06-05T22:00:04Z")

</div>

Ah, sorry for misleading, it might have been a recent addition. I suggest to look inside VCToolChain.cs to see what other build configuration options influence adding /EHsc switch and setting them to true for your project/target.

---

<div class="post-metadata">

**Author:** ![adelesky\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adelesky\_1](https://forums.unrealengine.com/u/adelesky_1)\
**Post date:** [June 5, 2014, 10:01pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/7 "2014-06-05T22:01:52Z")

</div>

No worries. 🙂

I’ll take a look at the tool chain and see if that will fix the issue.

---

<div class="post-metadata">

**Author:** ![adelesky\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@adelesky\_1](https://forums.unrealengine.com/u/adelesky_1)\
**Post date:** [June 5, 2014, 10:05pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/8 "2014-06-05T22:05:19Z")

</div>

Ah, it looks like bForceEnableExceptions is a member in the UEBuildConfiguration.cs file

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_64b73464](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_64b73464](https://forums.unrealengine.com/u/anonymous_user_64b73464)\
**Post date:** [August 21, 2014, 1:01pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/9 "2014-08-21T13:01:29Z")

</div>

Hi

did that work for you? I tried that on a Mac using Xcode and it was ignoed using Unreal 4.4.  
It seems that if you build for Mac and iOS that its hardcoded to have --no-exceptions as compiler flag. I tried to modify this in UnrealEngine/Engine/Source/Programs/UnrealBuildTool/IOS/IOSToolChain.cs  
and compiled UnrealEditor using XCode. This solved the compiler errors so far but the Xcode project file generation did not work that well and created a project with 26 targets which comiles insanly slow.

It would be great if the build tool chain would respect the mentioned config. params so there wouldn’t be a reason to compile unreal editor on your own.

Has anybody experiences with this issue?

thanks  
ciao

---

<div class="post-metadata">

**Author:** ![getnamo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/getnamo/32/1194624_2.png) [@getnamo](https://forums.unrealengine.com/u/getnamo)\
**Post date:** [January 23, 2015, 1:52am UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/10 "2015-01-23T01:52:02Z")

</div>

is there an alternative way to handle exceptions in third party libraries? Why is this not enabled by default?

---

<div class="post-metadata">

**Author:** ![RCL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RCL](https://forums.unrealengine.com/u/RCL)\
**Post date:** [January 23, 2015, 4:29am UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/11 "2015-01-23T04:29:02Z")

</div>

You can compile the third party library with exceptions enabled, assuming that it catches them itself. If its API mandates that you need to catch exceptions thrown by the library, then it’s a bad design since exceptions crossing dynamic library boundaries is an unreliable feature that will only work if the library in question is using the same C++ runtime.

---

<div class="post-metadata">

**Author:** ![Elringus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/elringus/32/1017568_2.png) [@Elringus](https://forums.unrealengine.com/u/Elringus)\
**Post date:** [April 7, 2016, 12:00pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/12 "2016-04-07T12:00:35Z")

</div>

Adding this:

```
UEBuildConfiguration.bForceEnableExceptions = true;

```

Inside the {ProjectName}.Build.cs constructor seems to solve the problem.

Thanks to [this open source project](https://github.com/GameTechDev/UE4RealSensePlugin/blob/master/Plugins/RealSensePlugin/Source/RealSensePlugin/RealSensePlugin.Build.cs#L11) for the hint 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7fc29bae](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7fc29bae](https://forums.unrealengine.com/u/anonymous_user_7fc29bae)\
**Post date:** [August 4, 2016, 1:48pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/13 "2016-08-04T13:48:34Z")

</div>

that did the trick for me, thanks 😉

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2709d010](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2709d010](https://forums.unrealengine.com/u/anonymous_user_2709d010)\
**Post date:** [February 3, 2017, 10:24am UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/14 "2017-02-03T10:24:09Z")

</div>

Thanks, that works for me too. Epic should not make it difficult for us to put at least a crash handler in C++ functions. Debugging of shipping versions is hard enough. A crash handler is a minimum requirement

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4235cc8e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4235cc8e](https://forums.unrealengine.com/u/anonymous_user_4235cc8e)\
**Post date:** [October 6, 2017, 2:37am UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/15 "2017-10-06T02:37:11Z")

</div>

I had added some try/catch statements to my code after which I could no longer package a build. Adding this statement to the build.cs in the constructor worked for me. Thank you.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_24cff47d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24cff47d](https://forums.unrealengine.com/u/anonymous_user_24cff47d)\
**Post date:** [January 11, 2018, 11:38pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/16 "2018-01-11T23:38:53Z")

</div>

For 4.16 and newer, you need:

```
bEnableExceptions = true;

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_bed5619a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bed5619a](https://forums.unrealengine.com/u/anonymous_user_bed5619a)\
**Post date:** [March 14, 2018, 11:59pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/17 "2018-03-14T23:59:02Z")

</div>

For Unreal 4.18 in the [ProjectName].Build.cs file, the constructor parameter is now ReadOnlyTarget rules and I got an error using: bForceEnableExceptions = true;  
I made it work by editing [ProjectName].Target.cs in the directory above. Adding bForceEnableExceptions = true; there fixed my build so I could use exceptions.

---

<div class="post-metadata">

**Author:** ![stojke-y](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stojke-y](https://forums.unrealengine.com/u/stojke-y)\
**Post date:** [March 27, 2018, 3:22pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/18 "2018-03-27T15:22:25Z")

</div>

Just tested this, it works! And it also works for plugins.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_127df0b6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_127df0b6](https://forums.unrealengine.com/u/anonymous_user_127df0b6)\
**Post date:** [April 13, 2018, 9:06am UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/19 "2018-04-13T09:06:01Z")

</div>

But this broke again with 4.19.  
Anyone having a solution?

---

<div class="post-metadata">

**Author:** ![poke1103](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@poke1103](https://forums.unrealengine.com/u/poke1103)\
**Post date:** [May 27, 2018, 1:50pm UTC](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934/20 "2018-05-27T13:50:15Z")

</div>

Yes it is broken in 4.19.

[Next page](https://forums.unrealengine.com/t/how-can-i-enable-unwind-semantics-for-c-style-exceptions/284934.md?page=2)
