不显示列表值的异常
Exception not showing list values
在我的异常 class 中,我传递了一个 IpAddresses 的 IEnumerable。当抛出异常时,这就是我所看到的。
为什么它不给我一个选项来查看我的 IEnumerable 中的值?
这是导致问题的代码:
public class CustomException : Exception
{
public List<string> IpAddresses { get; private set; }
public CustomException(string message, IEnumerable<string> ipAddresses)
: base(message)
{
IpAddresses = ipAddresses;
}
}
提前致谢。
可能您在 Exception.Data
字典中有键冲突:
Avoid key conflicts by adopting a naming convention to generate unique keys for key/value pairs. For example, a naming convention might yield a key that consists of the period-delimited name of your application, the method that provides supplementary information for the pair, and a unique identifier.
Suppose two applications, named Products and Suppliers, each has a method named Sales. The Sales method in the Products application provides the identification number (the stock keeping unit or SKU) of a product. The Sales method in the Suppliers application provides the identification number, or SID, of a supplier. Consequently, the naming convention for this example yields the keys, "Products.Sales.SKU" and "Suppliers.Sales.SID".
Mybe microsoft page 可以帮助你。
我找到问题了!这是我完全掩盖的事情。该异常被作为一般异常捕获
catch (Exception ex)
{
}
因此,由于它被强制转换为一般异常,因此未显示该值。
在我的异常 class 中,我传递了一个 IpAddresses 的 IEnumerable。当抛出异常时,这就是我所看到的。
为什么它不给我一个选项来查看我的 IEnumerable 中的值?
这是导致问题的代码:
public class CustomException : Exception
{
public List<string> IpAddresses { get; private set; }
public CustomException(string message, IEnumerable<string> ipAddresses)
: base(message)
{
IpAddresses = ipAddresses;
}
}
提前致谢。
可能您在 Exception.Data
字典中有键冲突:
Avoid key conflicts by adopting a naming convention to generate unique keys for key/value pairs. For example, a naming convention might yield a key that consists of the period-delimited name of your application, the method that provides supplementary information for the pair, and a unique identifier.
Suppose two applications, named Products and Suppliers, each has a method named Sales. The Sales method in the Products application provides the identification number (the stock keeping unit or SKU) of a product. The Sales method in the Suppliers application provides the identification number, or SID, of a supplier. Consequently, the naming convention for this example yields the keys, "Products.Sales.SKU" and "Suppliers.Sales.SID".
Mybe microsoft page 可以帮助你。
我找到问题了!这是我完全掩盖的事情。该异常被作为一般异常捕获
catch (Exception ex)
{
}
因此,由于它被强制转换为一般异常,因此未显示该值。