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

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jimcooper
Date:
Sun Aug 30 01:00:47 2015 +0000
Commit message:
Simple code that shows how exception handling doesn't have to change your code.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
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;
+}
diff -r 000000000000 -r 734e491b2c6e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Aug 30 01:00:47 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c
\ No newline at end of file