Search Unity

What is a "UnityException" and is there any reason to use it over C#?

Discussion in 'Scripting' started by Sun-Dog, Mar 22, 2018.

  1. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    A quick search on UnityException doesn't reveal much.

    I just noticed that there are "unity exceptions"

    EG:
    Code (csharp):
    1.  
    2.  
    3.         if (thing.otherThing == null)
    4.         {
    5.             throw new UnityException("The other thing is null");
    6.         }
    7.  
    (Where did I see this?? The adventure game tutorial codebase??)

    I was just curious is someone has any thoughts on it.

    The documentation is overwhelming in its volume of information:
    https://docs.unity3d.com/455/Documentation/ScriptReference/UnityException.html

    UnityException.png
     
  2. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Last edited: Mar 22, 2018
  3. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,997
    It inherits from Exception, so there's no harm using it, or not. Looks like a standard "may as well" thing: maybe you want to catch Unity errors specially, this lets you. Most functions that throw unity-specific errors probably throw it, since you always make your own exception classes.

    That code snippet looks like typical "here's a simple example _showing_ it in use, which no one would ever do for real."

    I'm guessing the docs are made by a tool. It lists unityException since it's there, not because it's something anyone needs to know about.
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    That documentation page is the best thing I've seen all year.
     
    HypeRR_ likes this.
  5. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    Thanks! I'm not up to the stage of dissecting the engine. I appreciate the look in.