gpt4 book ai didi

c# - 引用方法和异常类(c#、.net)

转载 作者:太空宇宙 更新时间:2023-11-03 19:30:15 25 4
gpt4 key购买 nike

我有一个带有方法的类,我想在该方法中抛出一个异常。在这里我想引用抛出异常的方法和类,以便更容易找到错误的来源。

public class SomeClass
{
public void SomeMethod()
{
(..)
Throw new Exception("An error occurred. Method:" + ?? + ", Class:" + ?? +");
}

最佳答案

你不需要那样做。查看 try-catch block 中异常的 StackTrace 属性。

关于c# - 引用方法和异常类(c#、.net),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5503229/

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