C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc

I’m getting the following build error when I’m trying to package my game:

Error C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc

These errors originate from the Boost library that I’m trying to build with my project, and the errors happen everywhere that they use their “BOOST_SYSTEM_NOEXCEPT” macro. These errors only occur when packaging, if I build in Development_Editor I don’t see these errors.

Is there a way I can fix these errors? How can I specify the /EHsc flag?

NOTE: Answers below will depend heavily on engine version, try many of them before you give up!

Did you find a solution yet? I’m also getting the same error here, can’t find a way out…

I fixed this by adding

UEBuildConfiguration.bForceEnableExceptions = true;

To my build.cs file.

yep, check my answer below

Thanks this saved my day.

Thank you!

I think the better solution here is to add the following to your build.cs file:

Definitions.Add("BOOST_SYSTEM_NOEXCEPT");

So that Boost will not insert “noexcept” everywhere, that way you don’t have to force enable exceptions for all modules.

Hi,

what if i have a bp project and not a c++ project? Where would i find build.cs? Please, i’m trying to package with a plugin which implements boost,

Thank you!

This is readonly now (4.17), so it can’t be done this way anymore. I followed RCL’s suggestion of hacking out UnrealBuildTool.exe instead, see How can I enable unwind semantics for C++-style exceptions? - Programming & Scripting - Unreal Engine Forums

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.

I had the same error but for the WFMedia module ONLY for client builds. What I did was added:

bEnableExceptions = true;

Into the Build file for that module only when building for windows. This fixed the build.

1 Like

Thank you!!! I’ve rebuilt several times and even tried disabling the WFMedia plugin… no idea why it’s throwing build errors about that.

This doesn’t help at all.

Strangely this didn’t work for me on 4.19. I just removed the WFMedia plugin folder and now it builds though.

In 4.19.2 none of the above answers will fix this issue if you build in shipping mode on Visual Studios 17.

In order to fix this, you must add a line to Engine/Source/Programs/UnrealBuildTool/Platform/Windows/VCToolChain.cs inside the function AppendCLArguments_Global:

        Arguments.Add("/EHsc");

This line will handle the compiler exception and you should be good to go! :smiley:

In 4.19.2, the probably best way to do this is in the MyProject.Build.cs file, just by adding bEnableExceptions = true;.
But yea it is completely non-obvious and it took me hours to find a solution that works… But I think this is the one to go, as no global toolchain files have to be modified.

using UnrealBuildTool;
public class MyProject : ModuleRules
{
public MyProject(ReadOnlyTargetRules Target) : base(Target)
{
	PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
            bEnableExceptions = true; // Add this...

    PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
}
}

Actually, the solution is slightly easier and you don’t need to modify the global toolchain file. See my answer below.

I have VS 2017 of course! So it’s weird that this doesn’t work for you?

Funny you should mention that. I tried that. It doesn’t work in 4.19.2 when you have visual studios 2017. :confused: Hence the adding of the compiler argument into the toolchain.

Odd! Have you tried running a shipping build? Because your solution works fine until you build shipping, at which point it produces the error.