energia / tivac-core

7 stars 17 forks source link

Add try...throw...catch Support for Stellaris #30

Closed robertinant closed 4 years ago

robertinant commented 7 years ago

From @rei-vilo on February 18, 2014 16:30

The following sketch for Stellaris raises an error when compiling:

Exception handling disabled, use -fexceptions to enable

By default, Energia states -fno-exceptions. Changing -fno-exceptions for -fexceptions throws even more errors:

Undefined reference to 'cxa_allocate_exception' Undefined reference to 'cxa_throw' Undefined reference to 'cxa_end_cleanup' Undefined reference to 'cxa_begin_catch' Undefined reference to 'cxa_end_catch' Undefined reference to 'typeinfo for int' Undefined reference to 'cxa_end_catch'

Exceptions management is critical for large projects, made possible by the Stellaris now Tiva C LaunchPad.

Sketch code

void setup() {
    Serial.begin(9600);

    try
    {
        throw 20;
    }
    catch (int e)
    {
        Serial.print("An exception occurred. Exception Nr. ");
        Serial.println(e, DEC);
    }
}

void loop()
{
    ;
}

See http://www.cplusplus.com/doc/tutorial/exceptions for more details on exceptions.

Copied from original issue: energia/Energia#325

robertinant commented 4 years ago

No plans to add this. If the user really need it he/she can add -fexceptions to platform.txt