C# equivalent to Java's Exception.printStackTrace()?

后端 未结 8 1430
刺人心
刺人心 2021-01-31 13:13

Is there a C# equivalent method to Java\'s Exception.printStackTrace() or do I have to write something myself, working my way through the InnerExceptions?

8条回答
  •  余生分开走
    2021-01-31 13:48

    Since @ryan-cook answer didn't work for me, if you want to print the stack trace without having an exception, you can use:

    System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();
    Console.WriteLine(stackTrace)
    

    Unfortunately, this can't be done in a PCL or in a .NETStandard Library

提交回复
热议问题