C# equivalent to Java's Exception.printStackTr

2020-05-18 04:33发布

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条回答
家丑人穷心不美
2楼-- · 2020-05-18 05:02
  catch (Exception ex)
{
    Console.WriteLine(ex.StackTrace);
}
查看更多
孤傲高冷的网名
3楼-- · 2020-05-18 05:03

I would like to add: If you want to print the stack outside of an exception, you can use:

Console.WriteLine(System.Environment.StackTrace);
查看更多
登录 后发表回答