yotiky Tech Blog

とあるエンジニアの備忘録

投げっぱなしのタスク処理(async void、UniTask.Void、Forget)

    async void Awake()
    {
        try
        {
            Debug.Log("async void");
            await UniTask.Delay(5);
            throw new Exception($"async void exception : frame {Time.frameCount}");
        }
        catch (Exception e)
        {
            Debug.LogError("catch exception:" + e.Message);
        }
    }

    private void Start()
    {
        try
        {
            UniTask.Void(async () =>
            {
                Debug.Log("Void");
                await UniTask.Delay(5);
                throw new Exception($"Void exception : frame {Time.frameCount}");
            });

            Hoge().Forget();
        }
        catch (Exception e)
        {
            Debug.Log("catch exception:" + e.Message);
        }
        
    }
    
    private async UniTask Hoge()
    {
        Debug.Log("Forget");
        await UniTask.Delay(5);
        throw new Exception($"Forget exception : frame {Time.frameCount}");
    }