Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails rescue_从重新升起异常_Ruby On Rails - Fatal编程技术网

Ruby on rails Rails rescue_从重新升起异常

Ruby on rails Rails rescue_从重新升起异常,ruby-on-rails,Ruby On Rails,我继承了一个项目,以前的开发人员将此添加到应用程序控制器: rescue_from Exception, :with => :render_500 我认为这是为了捕捉到这一点,并呈现一个动态页面。静态页面是不可接受的,但我现在不确定为什么会这样。在任何情况下,这都会破坏我捕获异常的能力。呈现动态错误页面后,是否有任何方法重新引发异常 我试过这个: def rescue_from(exception) respond_to |format| format.html { #ren

我继承了一个项目,以前的开发人员将此添加到应用程序控制器:

rescue_from Exception, :with => :render_500
我认为这是为了捕捉到这一点,并呈现一个动态页面。静态页面是不可接受的,但我现在不确定为什么会这样。在任何情况下,这都会破坏我捕获异常的能力。呈现动态错误页面后,是否有任何方法重新引发异常

我试过这个:

def rescue_from(exception)
  respond_to |format|
    format.html { #render the page# }
  end
  raise exception
end

然而,这显然是行不通的。有什么想法吗?

你能在启动或救援中引发异常,并在确保中做出响应吗

我在下面提供b),因为我不确定a)是否有效。显然,您可以导致在b)示例中引发的任何异常进入rescue块,然后引发传入的异常

要么:

(a)

(b)


像这样的东西应该有用-

rescue_from Exception, :with => :render_500

def rescue_500(exception)
    raise exception
end

查看一下,如果这不起作用,应该可以帮助您找到解决方案。

您可以手动发布到Exception,而不是尝试重新提升并获取Exception以捕获并发布

def rescue_from(exception)
  ::Exceptional::Catcher.handle(exception)
  respond_to |format|
    format.html { #render the page# }
  end
end

我的错误是没有仔细阅读这个问题。也就是说,很多人不看这些文件,把它们指向那个方向会有帮助。不用担心,伙计。谢谢你的回复。干杯我只是想说些类似的话:)。这很有效!谢谢你,杰西!对于将来遇到此问题的任何人,请确保为您的开发环境启用Exception,否则这将不起作用。
rescue_from Exception, :with => :render_500

def rescue_500(exception)
    raise exception
end
def rescue_from(exception)
  ::Exceptional::Catcher.handle(exception)
  respond_to |format|
    format.html { #render the page# }
  end
end