query exception handling