Close scope when raising exception