Search Unity

How to capture errors and send custom messages to Game Performance Reporting?

Discussion in 'Unity Cloud Diagnostics' started by TitanUnity, Feb 23, 2017.

  1. TitanUnity

    TitanUnity

    Joined:
    May 15, 2014
    Posts:
    180
    I'm trying to clean up our project and eliminate as many outstanding errors as possible. Game Performance reporting has been helpful to find the most common issues users encounter, but in some cases the error reported is not enough information for us to figure out exactly what's wrong. He's an example where we have a null exception firing within one of our coroutines, unfortunately there are a lot of moving parts within this call and we're not exactly sure what's wrong:
    Null.JPG

    I can easily perform some basic null checking to prevent these errors from spamming the console but that doesn't help us get to the root of what could be a larger issue. Ideally I want to be able to null check, and throw an error to Game Performance Reporting so we can see a custom message. I might be reading it incorrectly but it seems that if I wrap code in a try-catch block and throw my own errors that these messages will not be captured by Game Performance Reporting.

    Do you have a recommended practice for how I can get more information on an error like this? I was looking for something roughly like this:
    Code (CSharp):
    1. if(testObj == null)
    2. {
    3.     throw custom error to Game Performance Reporting ("blah blah")
    4.     return;
    5. }
    6.  
    7. // continue normal logic here
    8.  
    9.  
    10. if(testObj2 == null)
    11. {
    12.     throw custom error to Game Performance Reporting ("yada yada")
    13.     return;
    14. }
     
  2. thomasn_unity

    thomasn_unity

    Unity Technologies

    Joined:
    Jun 21, 2016
    Posts:
    60
    Hi TitanUnity,

    You can use Debug.LogException to report any exception to the Game Performance service.

    Code (CSharp):
    1. if(testObj == null)
    2. {
    3.     Debug.LogException(new Exception("testObj was null"));
    4.     return;
    5. }
    6.  
    It accepts any type that derives from Exception.
     
  3. TitanUnity

    TitanUnity

    Joined:
    May 15, 2014
    Posts:
    180
    Oh perfect, thanks a bunch.
     
  4. berzerk

    berzerk

    Joined:
    Dec 23, 2014
    Posts:
    18
    Hello Thomas,

    I was searching on Google for this same question and I found your answer. My suggestion is that you include a method call in the PerformanceReporting class (or Analytics class) as a stub for the LogException() method - sort of a shortcut.

    This will save time to a lot of devs that are not aware it works this way.

    Thanks!


     
  5. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144