Catching null pointer in queries with wrong field