- Home /
How to prevent repeating exceptions in console for async void method?
If I attach the following MonoBehaviour to an active GameObject (e.g. Camera) and then start the application (play in Editor), I get an indefinitely repeating exception logging in the console of the Editor. I would expect that it would log the exception once and not continuously repeating it.
using System;
using System.Threading.Tasks;
using UnityEngine;
public class TestController
: MonoBehaviour
{
[SerializeField]
private int m_counter;
public async void TestIt()
{
if(m_counter > 0)
{
return;
}
await Task.Delay(1);
++m_counter;
throw new Exception("Once");
}
private void Update()
{
TestIt();
}
}
The field m_counter stays at 1. So no new exception is thrown. It doesn't even stop when I stop playing the app. It will continue to spam the console in the Editor. I have to restart the Editor to stop it.
Can somebody explain to me why this is the case and how I can prevent it? I'm using the Unity Editor 2018.3.3f1 on Linux.
Answer by thomh_unity · Mar 05, 2019 at 10:02 AM
Hi Dravere,
It looks like you've run into this issue. We're testing a fix for this at the moment and hope to have it released in a future version.
If this is a serious problem for you then you might consider using 2018.3.2 where this issue does not occur.
Thom
Unity Support
Thank you very much for the answer. Wasn't expecting one after all this time. And yes, 2018.3.2 fixes the problem! It is not exactly a serious problem but at times quite an annoying one.
Your answer
Follow this Question
Related Questions
How to make a file run if a void has undefined coordinates? 1 Answer
TypeLoadException Error with Unity IAP,TypeLoadException Error when implementing Unity IAP 0 Answers
Google Play prelaunch test - java.lang.SecurityException 0 Answers
precompiledassemblyexception error 0 Answers
Sound Problem ! 1 Answer