Exception handling

20 Feb 2010

Hi all

I'm trying to port some code with a try ... catch block for exception handling, and get the message "Support for exception handling is disabled; use --exceptions to enable (E540)".

Would it be normal to have exception handling available for use with a device like the mbed, or does this add some kind of unacceptable overhead?

If it would be ok, how do we access the switch - I'm guessing that a lot of options are locked down because of the web interface to the compiler.


PS I never did like "on error goto" so please don't tell me that's a workaround ;-)

20 Feb 2010

Hi Daniel,

The conventional wisdom (and the advice from the armcc compiler guys) is that the overhead of exceptions is pretty high and therefore not appropriate for this sort of domain. For now, we are therefore not supporting exceptions (it is hard to remove support, but easy to add it).

We'll definitely look at really understanding the space and time overheads at some point (mbed isn't really conventional, so perhaps exceptions are perfect!), but for now you'll have to stick to more conventional exception handling approaches.


18 Oct 2010

Hi Simon,

I wonder if exceptions handling is available meanwhile.

Could you please give me a status?

Thank you in advance and best regards


18 Oct 2010

Hi Juergen,

We don't support exception handling in the compiler, and it is not planned to add it. But i'd be happy to hear about how you usually use them in your microcontroller applications, or your experiences! But for now, you will have to turn to more standard C solutions.



19 Oct 2010

Hello Simon,

thank you for your answer. Unfortunately my robotics specialist who developped a 3-axis robotic conversion matrix  calculation  for me where "divide by zero, ..." errors in the matrix calculation should be catched, checked the mbed infos before starting the software development and found support of exception handling for mbed:

He found there: http://mbed.org/handbook/mbed-Compiler the link to the "ARM RVDS (v4.0)" :


where under "Accurate Code Generation" he found:

"[...] The default library selected by the ARM Compiler offers a full complement of C/C++ functionality, including C++ exception handling and IEEE 754 floating point support. [...]"

Whith this info he relied on "exception support" for mbed and developped the libraries and program accordingly.

It seems that our robtics programming expert relied on the info on mbed homepage and we wasted a lot of money if exceptions are not supported. To remove the exceptions will cost us additiononal money and we will have worse functionality.

Do you have a solution for me with exception-support to compile the code perhaps locally or so?

Please take into account that I'm not a software speciallist, more a beginner.

If mbed does not plan to support exceptions please update the homepage and clearly point out this to avoid other users to waste time and money.

Thank you very much for your help in adance and best regards




19 Oct 2010

Hi Jurgen,

Thanks for the information and use cases; very useful.

I've updated the compiler page to include "in the default configuration". For exceptions, the default configuration is no exceptions unfortunately, and this is especially appropriate for microcontrollers. The full RVDS compiler toolchain does have a wealth of options you can add (all sorts of knobs, tweaks, variables!), and we don't intend on exposing these. Our intention is to be a full but lightweight compiler toolchain without all the quirks and options, so everyone is playing to the same rules.

Others have had some success using the Keil compiler when they wanted to go offline (that is also based on RVDS compiler), and this provides access to and support for all these different types of options. You can see this example and a keil appnote they published. There is an eval version of the tool too, so you should be able to test it out too, so maybe this could be a good solution to try.

I will continue to look at whether the cost trade-off means we can introduce exceptions by default; I know the ARM RVDS team have been doing some great work on improving C++ performance, so will go and meet them again soon to get their advice. But I don't want to promise anything, so for now we do not support exceptions.

Hope that clears things up,


19 Oct 2010

Is the zero division the only thing you needed exceptions for? Can you show some fragments of your code using exceptions?

I think you should be able to catch zero division with signal handlers and setjump/longjump. Or maybe you can set FP configuration to produce no exceptions on zero divide.

19 Oct 2010

Easiest solution I can think of is to reimplement the div0 handler so it doesn't send an exception & just returns zero (say)

It's detailed here & here

20 Oct 2010

Hi Simon,

thank you very much for your answer.

My suggestion would be a switch to turn on exceptions:

a) default: "exceptions off"  with all the positive small codesizes we see today.

b) "exceptions on" when somebody like me would need it and can accept bigger codesizes.

Thank you very much in advance and best regards


28 Jul 2011

I too would like to chime in here and request an option to turn exceptions on or off. There are times when I am trying to port a third-party library that uses exceptions, and it can quite a task to remove and/or replace the code with non-exception handling code.

As a bonus, I would like see other compiler options exposed as well. Particularly a way to turn off GNUC compatibility, since it really isn't fully compatible. One example is the Pawn scripting language which uses the GCC 'labels as values' feature to speed up the interpreter loop, but the RVDS compiler does not support this.

Thank you, Tyler

Please log in to post a reply.