Simple code that shows how exception handling doesn't have to change your code.

Dependencies:   mbed

main.cpp

Committer:
jimcooper
Date:
2015-08-30
Revision:
0:734e491b2c6e

File content as of revision 0:734e491b2c6e:

#include "mbed.h"


int main()
{
    Serial  console(USBTX, USBRX);

    try
    {
        int z  = 0;
        int x = ( 1 / z );
        console.printf("%d", x); // Should never get here.
        return true;
    }
    catch(...)
    {
        // x and z are cleaned up at this point.
        // console was defined outside of the try.
        // This is a good place to place a breakpoint if you are debugging or running emulation.
        console.printf("Something went wrong!  Terminating immediately.\n");
    }
    
    return false;
}