Page 1 of 1

C++ and exception handling

Posted: Wed Mar 01, 2017 1:56 am
by kolban
Was studying C++ and attempted to deliberately throw an exception to error proof a method I had written. Unfortunately when I use an un-modified ESP-IDF environment for compilation, I get the following compilation error:

Code: Select all

19:49:47 **** Build of configuration Default for project target ****
make all 
CXX WS2812.o
/home/kolban/esp32/esptest/apps/workspace/target/components/cpp_utils/./WS2812.cpp: In constructor 'WS2812::WS2812(int, uint16_t, int)':
/home/kolban/esp32/esptest/apps/workspace/target/components/cpp_utils/./WS2812.cpp:103:45: error: exception handling disabled, use -fexceptions to enable
   throw std::range_error("Pixel count was 0");
                                             ^
make[1]: *** [WS2812.o] Error 1
/home/kolban/esp32/esptest/esp-idf/make/component_wrapper.mk:176: recipe for target 'WS2812.o' failed
make: *** [cpp_utils-build] Error 2
/home/kolban/esp32/esptest/esp-idf/make/project.mk:386: recipe for target 'cpp_utils-build' failed
The source looks like:

Code: Select all

WS2812::WS2812(int dinPin, uint16_t pixelCount, int channel) {
	if (pixelCount == 0) {
		throw std::range_error("Pixel count was 0");
	}
Before I start looking into enabling the "-fexceptions" compilation flags, I am wondering if this feature was disabled on purpose. Is C++ exception throwing/handling not allowed in the ESP-IDF environment?

Re: C++ and exception handling

Posted: Wed Mar 01, 2017 6:49 pm
by grogmead
Generally when using c++ in embedded systems, a number of the potentially more expensive (in terms of memory, speed, or size) features are not included. Exception handling is often one of them. Some folks discussing pros/cons of exceptions in c++ for embedded systems can be found here: http://stackoverflow.com/questions/6911 ... ndling-add