Fix to set state.error before throw the exception