gpt4 book ai didi

C# 等同于 Java 的 Exception.printStackTrace()?

转载 作者:IT王子 更新时间:2023-10-29 03:40:14 25 4
gpt4 key购买 nike

是否有与 Java 的 Exception.printStackTrace() 等效的 C# 方法,或者我是否必须自己编写一些东西,通过 InnerExceptions 来处理?

最佳答案

试试这个:

Console.WriteLine(ex.ToString());

来自 http://msdn.microsoft.com/en-us/library/system.exception.tostring.aspx :

The default implementation of ToString obtains the name of the class that threw the current exception, the message, the result of calling ToString on the inner exception, and the result of calling Environment.StackTrace. If any of these members is null, its value is not included in the returned string.

请注意,在上面的代码中,不需要调用 ToString,因为有一个重载需要 System.Object 并调用 ToString直接。

关于C# 等同于 Java 的 Exception.printStackTrace()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/333953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com