• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by thorbrian · Dec 01, 2011 at 02:13 AM · editordebugexception

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Dec 01, 2011 at 02:47 AM 1
Share

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?

avatar image thorbrian · Dec 01, 2011 at 06:16 PM 1
Share

return would just return the current function, I want the exception behavior of killing the current event at a much higher level

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

No line numbers in stack trace 1 Answer

Setup parameters and play scene from editor script 1 Answer

VRAM Usage Debugging 1 Answer

Is it possible to access the previous UnityPlayer.log file at runtime before it get's overwritten? 0 Answers

How to get rid of the crash error in MonoDevelop 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges