Ruttie
Ruttie
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
thus causing the same issue again
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
which would then basically be equivalent to putting a yield return Method3() in Method1
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
one of the items returned from Method2 can be an IEnumerator
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
yes
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
well, if Method2 yield returns another enumerator, and that enumerator throws, my code won't work anymore
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
wdym? I never said this was wrong, I explicitly said:
I think I managed to solve the problem.
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
specifically:
yield return null;
IEnumerator coro;
try {
coro = Method2();
}
catch (Exception ex) {
obj._tcs.SetException(ex);
yield break;
}

while (true)
{
object current = null;
try
{
if (!coro.MoveNext())
break;

current = coro.Current;
}
catch (Exception ex)
{
obj._tcs.SetException(ex);
yield break;
}

yield return current;
}

obj.Complete();
yield return null;
IEnumerator coro;
try {
coro = Method2();
}
catch (Exception ex) {
obj._tcs.SetException(ex);
yield break;
}

while (true)
{
object current = null;
try
{
if (!coro.MoveNext())
break;

current = coro.Current;
}
catch (Exception ex)
{
obj._tcs.SetException(ex);
yield break;
}

yield return current;
}

obj.Complete();
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
yeah, that is what I'm doing
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
yup
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
note that Method1 also has a yield return null; at the start, so that control is immediately given to unity
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
Method1 is going into a StartCoroutine call
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
wdym?
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
I mean, this is what I tried, and it doesn't work
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
I'm not continuing the Method2 enumerator after an exception
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
I think unity may also be the problem, I thought it may be killing my coroutine on the exception
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
that doesn't actually work, since that will only catch any exceptions that happen before the first yield return
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
in which the try-finally is useful since I had hoped that would notify the completion source even if Method2 throws
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
which has currently resulted in me using a task completion source to observe the coroutine, and running Method2 in a separate coroutine 😅
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
the problem is that I don't want the main method to exit if Method2 throws an exception, but I can't simply do a try-catch around it
74 replies
CC#
Created by Ruttie on 10/29/2024 in #help
Try-catch in an iterator
yeah
74 replies