Exception handling on Teensy

Status
Not open for further replies.

lrtjosh

Active member
Hi,

I have some C++ code which can throw exceptions. When I build it in the Teensyduino IDE, I get this error:

error: exception handling disabled, use -fexceptions to enable

I found instructions saying you could customise the compiler flags by creating platform.local.txt in the same directory that already contains platform.txt, using directives such as:
Code:
compiler.cpp.extra_flags=-fexceptions
but I still get the same error.

Is it actually possible to enable exceptions, and if so, how do you do it?

Thanks!

Josh
 
@Frank B thanks, I've seen that information already. I've tried putting platform.local.txt in all the same locations as the various instances of platform.txt, in the TeensyDuino.app and Arduino.app bundles (on macOS) to no avail.

Keen to hear if anyone has done this successfully!
 
Probably simpler to just edit boards.txt (not platform.txt).

Find this line (or the one corresponding to the board you're using - this is for Teensy 4.1)

Code:
teensy41.build.flags.cpp=-std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing

and just change "-fno-exceptions" to "-fexceptions".

Maybe also keep in your mind an awareness that all of Teensy's libraries and examples have been developed and tested only with "-fno-exceptions".
 
Yes, but unfortunately this only works until the next update, and affects ALL programs...
I've given up modifying these files.. too much hassle every time.. Maybe I have also become lazy.
 
But it is easy to make work, at least for initial testing. Well, where "work" means the compiler args change as you wished... whether the libraries actually work and build a usable program is another matter.

Another quick tip is "show verbose output while compiling" in File > Preferences, to see the full compiler commands.

I also didn't know about the "local" override. Will be curious to hear if it works.
 
Wow..that works.
I've copied boards.txt to boards.local.txt and applied my changes.
I have two files now: boards.txt and boards.local.txt.
After restart, i have my old extended menu:
2020-11-18 21_54_09-Suche.png2020-11-18 22_06_23-Start.png
 

Attachments

  • boards.local.txt
    2 KB · Views: 81
  • platform.local.txt
    224 bytes · Views: 77
Last edited:
Thanks @PaulStoffregen, editing boards.txt directly worked. I'll keep experimenting to try and get it working with a local override.
 
Hmm not having any luck with that on macOS. Looking at the verbose output during compilation, my boards.local.txt is definitely not having an effect.

I like your idea of creating another board definition for the -fexceptions flag so I can switch per-project. Now I just need a way to do it that won't overwrite after each Teensyduino update :)

I'll stick with a quick edit of boards.txt for now.

Thanks for all your help. Cheers.
 
I've added my boards.local.txt to post#8
Maybe it's helpful?

Edit: ahh.. I see, you don't need to add the original boards.txt to the local variant.
Just add the NEW entries only.
Great.

Works for platform.local.txt, too.
 
Last edited:
Apple notarization, which is compulsory starting with Catalina, makes this sort of experimentation or editing anything inside the application bundle pretty dicey on MacOS. I recall the Arduino developers had issues with portable mode on MacOS due to signatures & notarization. Could be this is also not available on Macintosh?

I am curious to hear what does & doesn't work on Teensy if you compile with exceptions? Not that actually fixing those problems will be a priority... mainly just idle curiosity.
 
Status
Not open for further replies.
Back
Top