1========================================= 2C++ exceptions for long control transfers 3========================================= 4 5Normally Duktape uses ``setjmp()`` / ``longjmp()`` or their variants for 6internal long control transfers. One downside of these functions is that 7C++ automatic destructors (scope-based resource management, SBRM, a special 8case of RAII) in Duktape/C functions won't be executed which is awkward for 9C++ programmers. 10 11When ``DUK_USE_CPP_EXCEPTIONS`` (``DUK_OPT_CPP_EXCEPTIONS``) is defined, and 12both Duktape and application code is compiled using a C++ compiler, Duktape 13uses C++ ``try-catch`` and ``throw`` for internal long control transfers. 14This allows automatic destructors to run as expected. The config option is 15not enabled by default because C++ exceptions are sometimes disabled even 16when a C++ compiler is used (e.g. for performance reasons). 17 18The ``cpp_exceptions.cpp`` example illustrates how C++ exceptions can be 19used in Duktape/C functions at the moment: 20 21* Duktape uses C++ try/catch/throw internally; this is not visible to user 22 code directly. 23 24* Automatic destructors (scope-based resource management) work as expected. 25 26* C++ exceptions can be used in Duktape/C functions normally, but user 27 exceptions must be caught before they reach Duktape. If this is not 28 done, such exceptions are caught by Duktape and converted to API errors 29 (in other words, they won't propagate "through" Duktape at the moment). 30