0

我有以下控制器代码:

    [Route("")]
    public IHttpActionResult Get()
    {
        var actionContext = new ActionContext(this.Request);
        
        try
        {
            var command = new GetRootCommand();
            var root = this.commandMediator.Request(command).Data;

            this.linkProcessor.Process(root, actionContext);

            return
                this.Ok(root);
        }
        catch (Exception)
        {
            return this.InternalServerError();
        }
    }

代码分析器抱怨它并给出以下警告消息:

警告 CA1031
修改“获取”以捕获更具体的允许异常类型,或重新引发异常

看来这个控制器的目的是返回异常而不是重新抛出。我可以用投掷代替这个回报吗?如果我只想重新扔它,那么也许我什至不需要一开始就抓住它。

4

0 回答 0