README.md
1# Example: C++ exception handling
2
3(See the README.md file in the upper level 'examples' directory for more information about examples.)
4
5This example demonstrates usage of C++ exceptions in ESP-IDF.
6
7By default, C++ exceptions support is disabled in ESP-IDF. It can be enabled using `CONFIG_COMPILER_CXX_EXCEPTIONS` configuration option.
8
9In 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.
10
11The 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.
12
13**Note: Due to the use of the C++ exceptions, this example is written in C++ instead of C.**
14
15## How to use example
16
17### Hardware Required
18
19This example should be able to run on any commonly available ESP32 development board.
20
21### Configure the project
22
23```
24idf.py menuconfig
25```
26
27### Build and Flash
28
29```
30idf.py -p PORT flash monitor
31```
32
33(Replace PORT with the name of the serial port.)
34
35(To exit the serial monitor, type ``Ctrl-]``.)
36
37See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
38
39## Example Output
40
41```
42app_main starting
43In constructor, arg=42
44In constructor, arg=0
45In destructor, m_arg=42
46Exception caught: Exception in constructor
47app_main done
48```
49
50