0
\$\begingroup\$

I can check if coroutine still running by setting boolean variable outside the coroutine and then letting the coroutine itself set the value to true when it runs and set it to false when it decide to stop .

But this method of detecting whether coroutine still active or not doesn't work when the coroutine crashed due to error (invalid input, null reference , ect) because the boolean variable remain true while the coroutine itself has stopped due to error.

How do i check if coroutine still running or not in current frame ? i can't spend my code checking for next frame .

Preferably C# , but answer in javascript also accepted.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You're better off handling your errors at the source so your coroutines don't crash in the first place. This should not be a common or even rare occurrence in well-written code. \$\endgroup\$
    – DMGregory
    Oct 6, 2020 at 11:00
  • \$\begingroup\$ Or consider if you need a coroutine in the first place. In my experience, many problems you can solve with a coroutine are often solved far better by adding a separate script. \$\endgroup\$
    – Philipp
    Oct 6, 2020 at 12:30

1 Answer 1

1
\$\begingroup\$

Oh nevermind , the answer was to use try { } catch { } block

bool iscrashed = false;
IEnumerator Example() {

try {
//some operation
}
catch {
// if error encountered
iscrashed = true;
}

}
\$\endgroup\$
1
  • \$\begingroup\$ Weren't there some issues with yield inside try? \$\endgroup\$
    – Nikaas
    Oct 7, 2020 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .