相关疑难解决方法(0)

不像代码分析所描述的那样抛出和保留堆栈跟踪

做代码分析给了我CA2200项:

CA2200 Rethrow保留堆栈详细信息'func()'重新捕获捕获的异常并将其明确指定为参数.使用不带参数的'throw',以保留最初引发异常的堆栈位置.

我已经实现了这个建议,但无论如何我似乎都得到了相同的堆栈跟踪.

这是我的测试代码和输出(空格用于给出明显的行号):

第30行的预期错误

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace throw_test
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {
                try
                {


                    // line 22 below
                    throw new Exception();
                }
                catch (Exception ex) // DEFINES AND THROWS 'ex'
                {



                    // line 30 below
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.StackTrace);
            }

            Console.Read();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

产量

在c:\ Users\Richard\Documents\Visual Studio 2013\Projects\using_throw_closestream\using_throw_closestream\Program.cs中的throw_test.Program.Main(String [] args):第30行

第22行的预期错误

using System;
using …
Run Code Online (Sandbox Code Playgroud)

.net c# exception throw .net-4.5

8
推荐指数
2
解决办法
4415
查看次数

标签 统计

.net ×1

.net-4.5 ×1

c# ×1

exception ×1

throw ×1