refactored how to catch exceptions.  Added tests for the QueryFailure flag.