throw correct exceptions