Changed exception handling for queries.