Exception not showing list values

大憨熊 提交于 2019-12-13 19:41:25

问题


In my Exception class, I pass an IEnumerable of IpAddresses. When the exception is thrown, this is what I see.

How come it doesn't give me an option to see the values inside my IEnumerable?

Here's the code that's causing the problem:

public class CustomException : Exception
{
    public List<string> IpAddresses { get; private set; }


    public CustomException(string message, IEnumerable<string> ipAddresses)
        : base(message)
    {
        IpAddresses = ipAddresses;
    }
}

Thanks in advance.


回答1:


I figured out the problem! It was something I completely glossed over. The exception was being caught as a general Exception

catch (Exception ex)
{

}

So since it was being cast to a general exception, the value wasn't being displayed.




回答2:


Maybe you have a key conflict in the Exception.Data Dictionary:

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 the microsoft page could help you out.



来源:https://stackoverflow.com/questions/31920078/exception-not-showing-list-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!