- Home /
Can I throw an Exception that refers to a gameobject like Debug.Log does?
So when I call Debug.Log and friends, I can give it a gameobject such that clicking the message in the console window highlights the gameobject related to the message. Can I do a similar thing when throwing an exception? If so, how do I make such an exception?
...the reason I want this is because when a level designer makes some bad data - I want to be able to make it kill the code to make the problem obvious while making it easy for them to find where the bad data is to fix it. so far I've always been doing a Debug.Log to get the gameobject thing followed by an exception, but people still often miss the Debug.Log part...
thanks!
Using Debug.LogError does basically the same thing that happens when an uncaught exception floats to the top of the stack. Why can't you just use that, followed by return?
return would just return the current function, I want the exception behavior of killing the current event at a much higher level
Answer by Simon Says · Jul 11, 2013 at 08:07 AM
Um, when an exception is thrown, it gets logged through Debug.LogException() by Unity internally, with the GameObject that caused it already attached. So what you want should be happening already automatically. Click exception in the log once to highlight the culprit GameObject in scene hierarchy pane (press F to find it in the scene). Careful though, the highlight disappears after a time. To restore it, you need to click another log item and then the exception again. Double-clicking will normally take you to the script that caused the exception.
However, uncaught exceptions in scripts act like returns in Unity, basically. See this post for better explanation: http://answers.unity3d.com/questions/485595/uncaught-exception-doesnt-kill-the-application.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613061643im_/https://answers.unity.com/themes/thub/images/avi.jpg)