1.8.3 Exceptions system initialization

The exceptions system can be initialized either on demand (that is, when first used), or before entering main().

Initialization on demand has the advantage of not allocating heap memory unless the exceptions system is used, but has the disadvantage that it becomes impossible to throw any exception (such as std::bad_alloc) if the heap is exhausted at the time of first use.

The default behavior is to initialize on demand. To initialize the exceptions system before entering main(), include the following function in the link:

extern "C" void __cxa_get_globals(void);
extern "C" void __ARM_exceptions_init(void)
{
    __cxa_get_globals();
}

Although you can place the call to __cxa_get_globals() directly in your code, placing it in __ARM_exceptions_init() ensures that it is called as early as possible. That is, before any global variables are initialized and before main() is entered.

__ARM_exceptions_init() is weakly referenced by the library initialization mechanism, and is called if it is present as part of __rt_lib_init().

Note:

The exception system is initialized by calls to various library functions, for example, std::set_terminate(). Therefore, you might not have to initialize before the entry to main().
Non-ConfidentialPDF file icon PDF versionARM DUI0475M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.