Not catching an error with a try/catch block...

Hi guys,
I am trying to catch any errors while recording/accessing the mic but it doesn’t seem to catch this error and then the game breaks and I can’t click anymore buttons because of it.
Here is the code and error…does anyone know why? :frowning:

try {
                OnlineGameManager.Instance.currentGame.player1.attempt = Microphone.Start(null, false, (int)OnlineGameManager.Instance.currentGame.gameSound.audioClip.length + 1, 24000);
                _secsToWait = OnlineGameManager.Instance.currentGame.player1.attempt.length;
            } catch {
                _success = false;
            }
Failed to get record driver caps. result=60 (Error initializing output device. )
UnityEngine.Microphone:Start(String, Boolean, Int32, Int32)
<OnButtonRecordAttemptCoroutine>c__Iterator0:MoveNext() (at Assets/Scripts/GUI/Pages/OnlineHaveTurnPage.cs:68)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Thanks :slight_smile:

Looks like that method doesn’t actually throw an exception. Documentation says that the returned audio clip will be null if recording failed so you can check that instead.

1 Like

The error is a ‘error initializing output device’ and occurs before i could do a null check on it. I just checked and it actually IS catching the error and _success is set to false, but the error still occurs and breaks the game :frowning:

In what way?

Ah I think I found the problem :slight_smile:
I had a gui message pop up with an “OK” button, but the OK button wasn’t clickable and I thought that was because of the error…but it’s because of my own code and i wasn’t setting a bool back to false.
I haven’t been able to double check if that WAS it because the error is intermittent on my PC but I am pretty sure that was it :slight_smile:
Thanks

Yea never assume things, I can speak of experience :slight_smile: Always make sure if things really happen or not by adding a log in catch for instance, at least during development.