Are Debug.LogException() reported as exceptions in Cloud Diagnostic?

Hi,

From reporting my exceptions, I saw some weird errors that I think were inside a try() with a LogException() in the catch().

Before investigating in depth I was wondering, are the LogException() for example present in the catch() of the try() reported as real exceptions? In case there is a way to figure out that they are exceptions in a try() like a label telling you this or whatever?

If what user “ryanc-unity” said back in 2019 was still true. Then yes

Debug.LogException(new Exception("<Exception Message>"));

Looks like anything called with Debug.LogException would be sent to the service. I think internally, they hook to this same API as well: Unity - Scripting API: Application.logMessageReceived

If you manually try-catch it yourself, it is still informative to pass an exception to Debug.LogException just before continuing.

try
{
    ....
}
catch( Exception e )
{
    // Script flow is saved and still can continue from this point
    Debug.LogException( e ); // Perhaps will send to cloud service also.
}
2 Likes

Thanks for the info!

Actually went ahead and tried it. I will leave information here for future reader also.
In this experiment I tried both LogException manually and actual uncaught exception.

Note that this is RELEASE build, Mono scripting backend, PC - Windows X64 build.
As expected there will be no line number. Sadly, but had to live with it.

As you seen above, so knowing function name is only your friend here. So it is good practice to keep your function short (<20 lines?), instead of mega big 100+ lines function, just as most clean code practice suggested.

4 Likes

(Sorry to necro/dig the thread)

A little bit addition to this.
It seems like Debug.LogError will NOT produce cloud diagnostic event.

So if you have some kind of manual assert API and want it to send to cloud report when failed, you’d better use

Debug.LogException(new Exception(“Testing Cloud Diagnostics reports”));
To print the report rather than Debug.LogError

source:
https://docs.unity.com/cloud-diagnostics/en/manual/CrashandExceptionReporting/SettingupCrashandExceptionReporting

1 Like

For me, both using Debug.LogException or throwing the exception doesn’t make Cloud Diagnostics to capture the exception, in the build. The only case it captures the exception is throwing it, and in the editor (in play mode).

how to solve it?

I had to do a clean build to make it work.