Return appropriate exceptions for queries