Search Unity

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

Discussion in 'Unity Cloud Diagnostics' started by Francesco-FL, Sep 22, 2021.

  1. Francesco-FL

    Francesco-FL

    Joined:
    May 25, 2021
    Posts:
    176
    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?
     
  2. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    If what user "ryanc-unity" said back in 2019 was still true. Then yes

    Code (CSharp):
    1. Debug.LogException(new Exception("<Exception Message>"));
    https://forum.unity.com/threads/how-to-upload-crash-report-manually.749813/

    Looks like anything called with Debug.LogException would be sent to the service. I think internally, they hook to this same API as well: https://docs.unity3d.com/ScriptReference/Application-logMessageReceived.html

    If you manually try-catch it yourself, it is still informative to pass an exception to Debug.LogException just before continuing.
    Code (CSharp):
    1. try
    2. {
    3.     ....
    4. }
    5. catch( Exception e )
    6. {
    7.     // Script flow is saved and still can continue from this point
    8.     Debug.LogException( e ); // Perhaps will send to cloud service also.
    9. }
     
    Francesco-FL likes this.
  3. Francesco-FL

    Francesco-FL

    Joined:
    May 25, 2021
    Posts:
    176
    Thanks for the info!
     
  4. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    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.

    upload_2021-10-2_20-8-47.png
    =================================================================================

    upload_2021-10-2_20-9-6.png

    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.
     
    Last edited: Oct 2, 2021
  5. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    (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-diagno...Reporting/SettingupCrashandExceptionReporting
     
    ThomLaurent likes this.
  6. Stephanommg

    Stephanommg

    Joined:
    Aug 18, 2014
    Posts:
    88
    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).