Add error checking to the example