【问题标题】:catch block is returning to code inspite throw inside it c#catch 块正在返回代码,尽管在其中抛出 c#
【发布时间】:2015-10-04 22:37:24
【问题描述】:
if()
{
    if()
    {
    }
    else
    {
        throw new httpexception(404,page not found);
    }
}
else
{
    throw new httpexception(404,page not found);
}

内部完美地抛出 404,但是当控制转到外部块时,它返回到上面的代码,如果再次阻止并抛出 500 错误,执行这么多次之后。

【问题讨论】:

  • 你能不能更好地解释一下“它又回到代码并抛出500”?
  • 这个问题不清楚。你在说哪个catch块?那些 if 语句应该做什么?
  • 关于调试ctrl是回到if开始前写的代码
  • 我说的是外部 if,即使抛出 404 也不会到 404
  • 哪个catch块,多少线程,...

标签: c# model-view-controller http-status-code-404


【解决方案1】:

错误代码 500 是指您的服务器出现问题。问题是你抛出了一个 httpexception 并且没有 try catch 块来处理抛出的异常。

试试这个:

try{
    if()
    {
        if()
        {
        }
        else
        {
            throw new httpexception(404,page not found);
        }
    }
    else
    {
        throw new httpexception(404,page not found);
    }
catch (Exception){
// handle for when a 404 is thrown
}

http://www.checkupdown.com/status/E500.html

【讨论】:

  • 我也尝试了try catch块,但得到了相同的结果,控制权来到了外部else-->catch-->它来到了if条件上面的代码这些步骤一次又一次地发生并给出 500 错误
  • 它在循环内吗?请使用 try catch 块发布您的示例。
  • try{ if() { if() { } else { throw new httpexception(404,page not found); } } else { throw new httpexception(404,page not found); } catch (Exception e){ throw new httpexception(404,page not found);//最初尝试 throw e//第二次尝试}
猜你喜欢
  • 1970-01-01
  • 2016-12-11
  • 2018-11-18
  • 2011-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-18
相关资源
最近更新 更多