Is there a way to detect an error in the console?

I am making a game and errors will randomly pop up, I don’t know what it is. Random errors will pop up, I will run it once and there will be an error, and I will do the same thing and there isn’t one now. I really don’t know what the problem is. I was thinking, if I could detect an error message in the console, I could just give the player an error, then send them back to the main screen. So all I need to know is how do I detect errors or messages in the console?

I figured it out! If you are having this problem use this (this only works with errors and not messages and also put this in the update function)

UnityException exception = new UnityException();
if (exception.Message == "A Unity Runtime error occurred!") {
    //Do whatever you need after you get the error
}

I’m not sure what your code up there does. A brand-new exception won’t have a message on it so your if check is sorta meaningless.

You can output anything you want to the console with the Debug.Log() calls.

You can read everything that gets displayed to the console by hooking Application.logMessageReceived