Error: exception handling disabled, use -fexceptions to enable

error: exception handling disabled, use -fexceptions to enable
How to do this?

In your platformio.ini by adding the line build_flags = -fexceptions? If that doesn’t work, we need more info and a minimal example for what you’re trying to do. C++ exceptions in your firmware code?


C++ exceptions in your firmware code?

Not in my. But in ESP32 BLE library. But, yes, exceptions in code.

Well… Your solution is simple and work!
Just added:

; Build options
build_flags = -fexceptions

into platformio.ini and project built successfully.

But. This way is not documented / no samples in build_flags option description
There is table with assembler, linker, defines, etc. Not obvious (for not-pro, Arduino users, for example) to use options without -D, -W, etc. prefixes at all. All present samples with different prefixes only,
So, i suppose it would be good to add such, not prefixed sample into docs too.

Good to hear that it worked. You also can accept the answer to close this question as solved.

To be fair, at the end of the section “Dynamic build flags” you linked, there are several links to the GCC documentation pages, like “Options for Linking”, et cetera. -fexceptions could have been found in the “Options for Code Generation Conventions” part. I think its best to think of build_flags as a piece of text that gets copy-pasted in every gcc and g++ command, so you basically have fine-grained controll over all passed gcc/g++ switches there (together with build_unflags). Then again, for beginners, they might not have seen any full gcc command, since the Arduino IDE hides it away from them.

1 Like

I have read this gcc docs too.
And i understand, that i need to add “-fexceptions” flag somehow. But. For not-expirienced user, it is not so obvious that it can be added w/o prefixes, because all samples are with different prefixes. And, because both, Arduino IDE and VS Code IDE do not show full build commands in logs (at least by default) - there is no simple way to understand, how build string formed from this config params.
Of course, this is my IMHO. I just want nobody else have such stupid problem :slight_smile: