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

Dependencies:   mbed

Revision:
0:734e491b2c6e
diff -r 000000000000 -r 734e491b2c6e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Aug 30 01:00:47 2015 +0000
@@ -0,0 +1,24 @@
+#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;
+}