Hi
I have a WWWhelper class to get resources. In case of fails, we usually set a try/catch for it so it can notice user try again later.
IEnumerator TryGet(){
try{
//some codes here may throw exception
yield return StartCoroutine(WWWHelper.Get());
}
catch{
Debug.log("Oops");
}
}
Unfortunately, the Editor said
Cannot yield a value in the body of a try block with a catch clause
So how can I make it ?
Thank you
I think you should check this link, I feel it explains best what I’m trying to tell you : How do I return a value from a coroutine? - Unity Answers
A pretty clean way to manage try/catch with WWW is to have the helper coroutine exit normally regardless of result. Then have a getter for the response value, which throws an exception if there was an error.
IEnumerator TryGet()
{
WWWHelper helper = new WWWHelper();
yield return StartCoroutine(helper.Get());
try{
//some codes here may throw exception
helper.GetValue();
}
catch{
Debug.log("Oops");
}
}