CMake "cannot use 'try' with exceptions disabled"

I’m building JUCE using MSVC toolchain on Windows using CLion. Just hit this error. I can’t see a reference to no-exceptions in the CMakeLists.txt, could it be something in juceaide?

<path-to>\JUCE\modules\juce_events/messages/juce_MessageManager.cpp(323,5): error: *cannot use 'try' with exceptions disabled*
    try
    ^
1 error generated.
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\Llvm\bin\clang-cl.exe' : return code '0x1'
Stop.
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1424~1.283\bin\Hostx64\x64\nmake.exe' : return code '0x2'

I’m not sure exactly what’s going on here. Is the error appearing during configuration, or during the actual build?

It looks like you’re building with ClangCL rather than MSVC, and at the moment juce_recommended_config_flags will only supply -EHsc if the compiler is the ‘real’ MSVC, rather than another compiler pretending to be MSVC. Perhaps ClangCL also needs to see the -EHsc flag. To test this theory, you could try adding -EHsc to your CMAKE_CXX_FLAGS during configuration.

1 Like

Ah, yes you’re right, I’d set it to use ClangCL to see if that would fix another issue was I having (which turned out to be something else). I’ve now set it back to the default compiler. Problem solved. Thanks for the clue.