Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

how to throw exception?

Discussion in 'Scripting' started by tiny2014, Jul 13, 2014.

Thread Status:
Not open for further replies.
  1. tiny2014

    tiny2014

    Joined:
    Jun 28, 2014
    Posts:
    13
    in C # , we can using system and then throw exception.
    But in unity, is there any classes can use ?
    give me the link in the api manual.
     
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
  3. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    It has LogException ()
     
  4. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,573
    I believe the usual c# syntax works. It should print out to the console, at least I'm pretty sure.

    Code (CSharp):
    1. throw new Exception();
     
    trappist-1 likes this.
  5. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    916
    The usual syntax does indeed work, just add
    Code (csharp):
    1. using System;
    at the top.

    You can however, also use Debug.LogException and pass in an exception object, or use Debug.LogError and pass in a string with a message. Note though, that the last option doesnt abort execution and resumes with the next statement (which could end up throwing another, built-in, exception)
     
    landon912 likes this.
  6. tiny2014

    tiny2014

    Joined:
    Jun 28, 2014
    Posts:
    13
    can using system be used in other platform except windows?
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,307
    It has nothing whatsoever to do with Windows. All it does is import the System namespace; you don't need it for anything if you qualify stuff like System.Whatever anyway. It's just a coding convenience.

    --Eric
     
    l_a_create likes this.
  8. tiny2014

    tiny2014

    Joined:
    Jun 28, 2014
    Posts:
    13
    but I guess that the unity can't support the whole System NameSpace
    in my mind if unity support one namespace , it must can compile and build it to all the platform such as PS4 XB1 Win7 wii....

    so I just not sure if unity support it
     
  9. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,573
    The System namespace like most others, with a few exceptions, are usable on all platforms.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,307
    Not everything in System is included, which means the not-included stuff doesn't work on Windows either...Unity uses Mono, not .NET (except on WP8).

    --Eric
     
    l_a_create likes this.
Thread Status:
Not open for further replies.
unityunity