6 years, 10 months ago.

How can we activate try-catch in the web compiler?

I am using new and vectors in my code and I got some memory errors. Would like to control the way this happens with try and catch but i get a error 540

How can I activate and use try-catch

I don't think you can. Maybe try writing code without errors in? ;-) In all seriousness if you are having to get into that level of debugging then an offline IDE with proper debug capabilities is probably a good idea. The online system is great for quick hacks and sharing code but for anything complex it's like trying to code and debug with one hand tied behind your back.

posted by Andy A 13 Jun 2017

Thanks for the comments. Well call me a beginner but I am quite happy with the online IDE. Last monday I installed GCU ARM compiler in my windows 10 computer, and now it has become unusable :( The whole machine is totally unresponsive. Tried to use restore points and it seemed to work for a moment but now it has become even worse. :(

posted by Cristian Fuentes 14 Jun 2017

2 Answers

6 years, 10 months ago.

Avoid dynamic allocation on a microcontroller.

https://stackoverflow.com/questions/1725923/how-bad-is-it-to-use-dynamic-datastuctures-on-an-embedded-system

https://www.quora.com/Why-is-malloc-harmful-in-embedded-systems

Thanks for the comment. I will try and use static allocation. Just for the record (in case anyone is reading) there is a way to avoid using try -catch with the new operator. It is variable= new (nothrow) type[size] . Then if this fails, the system instead of throwing an exception , just returns NULL so we can just check If(variable==NULL) and manage it from there

posted by Cristian Fuentes 14 Jun 2017
6 years, 10 months ago.

Besides, try catch adds an incredible amount of code and run time overhead.