Error handling. How to??

Hi All

Is there any kind of formal error trapping in the Arduino code?

I cannot seem to find any reference to making your code bullet proof...

Any error objects, error handlers, trapping errors etc?


The most important question you can ask yourself is "what do/can/should I do if this error occurs". The answer to that question will define what you actually do.

Standard error handling techniques are really not all that relevant on the Arduino.

Don't know how others do it, usually I start sketches with a variable debug=1. With small routines run if debug =1 I test whether variables actually are updated correctly, whether I have enough time to complete a task, or show anything else that needs debugging. When I'm happy with the part I'm testing I change the if debug ==1 to if debug ==2 (or an non zero number), so the output won't appear on my terminal any more.

By changing the value of debug itself before compiling I can choose to run, not run, or run specific "debug"- routines if debug is a special number.

When there are no more errors (or when I'm satisfied enough ;)) I set the variable to zero and/or delete all debug-routines.

It's not rocket science and some errors can't be handled this way, but in 9 out of 10 cases it helps me getting rid of errors in my project.

When I try to add try/catch code to a sketch I get this:

error: exception handling disabled, use -fexceptions to enable

Haven't tried more than this, so can't tell you is fexceptions works or is allowed on the Arduino

As for assertions, they may work, but the usual response is to abort, which is awkward for a constantly-running program. You can easily write your own, though with a different response.