how to use try-catch in native code

1,110 views
Skip to first unread message

marin....@gmail.com

unread,
Apr 25, 2021, 4:24:24 PM4/25/21
to discuss-webrtc
Hi,

I want to use try-catch for testing purposes but when I try to build, I get "cannot use 'try' with exceptions disabled" message.

I tried a few things, but nothing helped.

Does anyone know how I can enable exceptions?

Thanks,
Marin

Kiran Thind

unread,
Apr 26, 2021, 11:13:33 PM4/26/21
to discuss...@googlegroups.com
This is hard to answer without knowing which language and platform. A few minutes on stack overflow will answer your question. For C++, in Visual Studio:


Using GCC/Clang, use the -fexceptions compile flag (making sure -fno-exceptions isn’t set as well):

In CMake:
set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -Wall -Werror -fexceptions -frtti")

On Apr 25, 2021, at 1:24 PM, marin....@gmail.com <marin....@gmail.com> wrote:

Hi,
--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/df9cff2d-88cc-4c04-86ad-be780d31b5f8n%40googlegroups.com.

Byoungchan Lee

unread,
May 9, 2021, 1:28:21 AM5/9/21
to discuss-webrtc
You can change the compilation flags by modifying the GN file.

See https://source.chromium.org/search?q=%22-fno-exceptions%22%20lang:gn%20f:build

However, Google's C++ code is written without C++ exceptions and I think it will not work properly if you enable exceptions.

marin....@gmail.com

unread,
May 10, 2021, 11:59:09 AM5/10/21
to discuss-webrtc
Thanks for comments. I managed to test my code without using exceptions.
Reply all
Reply to author
Forward
0 new messages