C
C#2y ago
rick_o_max

❔ Can't catch Unity Coroutine (IEnumerator) error

Hi! I'm running some Func inside a Unity Coroutine. I'm using an approach I've used before to get the errors the code might throw and handle them, but by some reason, I can't catch the errors. You guys have any idea why?
3 Replies
rick_o_max
rick_o_maxOP2y ago
This is the code that runs inside the Coroutine and executes a list of actions, theorically handling any error thrown ^ I've used this "trick" before, and it worked (not on this project):
try
{
next = enumerator.MoveNext();
}
catch (Exception e)
{
exception = e;
goto onError;
}
if (next)
{
yield return enumerator.Current;
}
try
{
next = enumerator.MoveNext();
}
catch (Exception e)
{
exception = e;
goto onError;
}
if (next)
{
yield return enumerator.Current;
}
YieldInvoke code:
public readonly Func<T, IEnumerator> Func;
public readonly T Context;

public IEnumerator YieldInvoke()
{
var awaitable = Context as IAwaitable;
if (awaitable != null)
{
awaitable.Completed = false;
}
yield return Func(Context);
if (awaitable != null)
{
awaitable.Completed = true;
}
}
public readonly Func<T, IEnumerator> Func;
public readonly T Context;

public IEnumerator YieldInvoke()
{
var awaitable = Context as IAwaitable;
if (awaitable != null)
{
awaitable.Completed = false;
}
yield return Func(Context);
if (awaitable != null)
{
awaitable.Completed = true;
}
}
I can't try-catch a Func inside an IEnumerator, is that it?
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server