Check if coroutine crashed

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.