如何在vs2012中的某个位置获取所有警告消息的列表

时间:2014-01-02 11:39:57

标签: c# .net visual-studio error-handling

我在c#.net项目中有一系列项目。我希望在一个地方而不是在单个页面中调试vs2012时所有警告消息的列表。在vs2012专业版中是否有任何插件或工具。

请注意,我需要警告消息列表而不是错误消息。如果除了内置工具之外还有一些第三方工具可以帮助您删除警告,请在答案中提及。主要关注的是所有警告的列表,以便我可以用更好的方法删除它们。

2 个答案:

答案 0 :(得分:0)

内置错误列表(http://msdn.microsoft.com/en-us/library/33df3b7a.aspx)有什么问题吗?

答案 1 :(得分:-1)

如果必须对每个集合元素执行异常危险操作,则:

  1. 实例化List<Exception>
  2. 使用foreach循环收藏。
  3. try catch块放在每个操作的循环中。
  4. 发生错误时,将Exception放入List<Exception>并继续。
  5. 结束时,使用AggregateException构建List<Exception>并重新抛出
  6. 所有这一切都来自以下样本:

    using System;
    using System.Collections.Generic;
    
    namespace ExceptionsSample
    {
        class Program
        {
            static void PerformUnsafeActionsWithCollection()
            {
                //ExceptionsList
                var allErrors = new List<Exception>();
                //Collection
                var integersArray = new int[16];
                //Cycle
                foreach (int i in integersArray)
                {
                    try
                    {
                        //Throws an exception (division by zero)
                        Decimal result = Decimal.Divide(i, 0);
                    }
                    catch (Exception exception)
                    {
                        allErrors.Add(exception);
                    }
                }
                if (allErrors.Count > 0) throw new AggregateException(allErrors);
            }
    
            static void Main(string[] args)
            {
                try
                {
                    PerformUnsafeActionsWithCollection();
                }
                catch(AggregateException aggregateException)
                {
                    foreach(Exception error in aggregateException.InnerExceptions)
                    {
                        Console.WriteLine("Error occured: {0}", error.Message);
                    }
                }
            }
        }
    }
    
相关问题