throw appropriate error