Adding error handler to sample code