Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
0
Question by ProtoTerminator · Dec 10, 2018 at 01:59 AM · exceptiondebuggingconsolestacktrace

throw exception override stacktrace double click log

With a custom exception, I'm trying to give it a stacktrace without throwing so I can throw it later (holding the same stack trace). The problem I'm having is the new StackTrace is providing a different output than throw Exception.StackTrace, most notably missing [0x00002] which I'm guessing is what Unity is using to jump to the line number in visual studio when double-clicking the log. Is there any way to do this and have the double-click functionality still work?


 public class MyException : Exception
 {
     public MyException(string stackTrace)
     {
         _stackTrace = stackTrace;
     }
 
     string _stackTrace;
 
     public override string StackTrace
     {
         get
         {
             return _stackTrace;
         }
     }
 }

 try
 {
     throw new Exception(); // double-click goes right here
 }
 catch (Exception e)
 {
     Debug.Log("StackTrace: {" + e.StackTrace + "}"); // output: "StackTrace: {  at TestScript.Awake () [0x00002] in /Users/lol_tim/New Unity Project/Assets/TestScript.cs:28 }"
     throw new MyException(e.StackTrace);
 }

 try
 {
     throw new MyException(new System.Diagnostics.StackTrace(0, true).ToString()); // double-click does nothing
 }
 catch (Exception e)
 {
     Debug.Log("StackTrace: {" + e.StackTrace + "}"); // output: "StackTrace: {   at TestScript.Awake() in /Users/lol_tim/New Unity Project/Assets/TestScript.cs:line 28}"
     throw new MyException(e.StackTrace);
 }
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 hexagonius · Dec 10, 2018 at 07:47 PM 0
Share

the is totally outside my knowledge, but I found this post where there's a little more going on concerning System.Diagnostics.Stacktrace. maybe it helps you:
https://answers.unity.com/questions/289006/catching-double-clicking-console-messages.html

avatar image ProtoTerminator hexagonius · Dec 13, 2018 at 05:39 PM 0
Share

Thanks, I read that before posting this question. I'm trying to work with the default console (any uncaught exception will get printed to it) which it looks like the top person couldn't figure out, either. I saw the last person compiles their $$anonymous$$yDebug to a .dll which made double-click go where they want, but unfortunately I can't do that from just throwing an exception.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ProtoTerminator · Dec 13, 2018 at 06:23 PM

It looks like I can get the double-click to work by substituting a gibberish code (not really sure what that's used for) and realigning the formatting to match, at least in english culture. I'm not sure if this works with non-english cultures (I tried changing my culture before running this code, but everything still came out in english for some reason). Of course this is extremely ugly and I wish there was a better way to do it.


 System.Text.StringBuilder sb = new System.Text.StringBuilder(new System.Diagnostics.StackTrace(0, true).ToString());
 sb.Remove(0, 1);
 sb.Append(" ");
 sb.Replace("(", " (");
 sb.Replace(") in", ") [0x00000] in");
 sb.Replace("\n ", " \n");
 sb.Replace("line ", string.Empty);
 newTrace = sb.ToString();
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
avatar image
0

Answer by AnKOu · Mar 28 at 02:16 PM

Convert an Exception stacktrace so that it keeps its links

         private const string format = "{0} in <a href=\"{1}\" line=\"{2}\">{3}:{4}</a>";
         private static string GetUnityFormatStacktrace(Exception pException )
         {
             string[] lines = pException.StackTrace.Split("\n");
 
             System.Text.StringBuilder builder = new System.Text.StringBuilder();
             for (int l = 0; l < lines.Length; l++)
             {
                 string currentLine = lines[l];
                 if (currentLine.Contains("Assets\\") == false)
                 {
                     builder.AppendLine(currentLine);
                     continue;
                 }
 
                 string[] pathLine = currentLine.Substring(lines[l].IndexOf("Assets\\")).Split(":");
                 string path = pathLine[0];
                 string line = pathLine[1];
                 string newLine = string.Format(format, currentLine.Split(" in ")[0], path, line, path, line);
                 builder.AppendLine(newLine);
             }
             return builder.ToString();
         }
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.

Follow this Question

Answers Answers and Comments

97 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get rid of certain warnings on the console. 1 Answer

UnityVS not breaking on exception and missing debug info 1 Answer

debugging android 3 Answers

Writing to Monodevelop's "Application Output" window 3 Answers

Asserts not working (Debug.assert or Assertions.Assert.xxx(xx.)) 1 Answer


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