esp-idf/examples/cxx/exceptions
Marius Vikhammer 8efb2bb1ed ci: run Example_GENERIC for C3
Add support for running example_GENERIC tests for C3 on label.

Fix examples that fail.
2021-05-20 14:32:47 +10:00
..
main Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00:00
CMakeLists.txt C++: Moved all C++ examples to own folder 2020-02-18 12:48:57 +08:00
example_test.py ci: run Example_GENERIC for C3 2021-05-20 14:32:47 +10:00
Makefile Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00:00
README.md C++: Moved all C++ examples to own folder 2020-02-18 12:48:57 +08:00
sdkconfig.defaults C++: Moved all C++ examples to own folder 2020-02-18 12:48:57 +08:00

Example: C++ exception handling

(See the README.md file in the upper level 'examples' directory for more information about examples.)

This example demonstrates usage of C++ exceptions in ESP-IDF.

By default, C++ exceptions support is disabled in ESP-IDF. It can be enabled using CONFIG_COMPILER_CXX_EXCEPTIONS configuration option.

In this example, the sdkconfig.defaults file sets the CONFIG_COMPILER_CXX_EXCEPTIONS option. This enables both compile time support (-fexceptions compiler flag) and run-time support for C++ exception handling.

The example source code declares a class which can throw exception from the constructor if the argument provided is equal to 0. This is used to demonstrate that exceptions can be thrown and caught using standard C++ facilities.

Note: Due to the use of the C++ exceptions, this example is written in C++ instead of C.

How to use example

Hardware Required

This example should be able to run on any commonly available ESP32 development board.

Configure the project

idf.py menuconfig

Build and Flash

idf.py -p PORT flash monitor

(Replace PORT with the name of the serial port.)

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Example Output

app_main starting
In constructor, arg=42
In constructor, arg=0
In destructor, m_arg=42
Exception caught: Exception in constructor
app_main done