kohana如何处理异常
我有一个关于 kohana 例外的问题。
我有一个想要投入生产的网站,并且我不希望简单地抛出异常(就像现在一样),但我想在发生异常时将用户重定向到另一个页面。
我使用 kohana 3,我想知道:如果发生异常,如何捕获异常并将用户重定向到另一个页面:
代码示例:
而不是
if ( ! $sale->loaded())
{
throw new Kohana_Request_Exception('Sale not found.');
}
我想要的:类似:找不到页面。
谢谢你!
I have a question about kohana exceptions.
I have a site that I want to put in production, and I don't want the exceptions to be simply thrown (like they are now), but I want to redirect the user to another page in case of an exception occured.
I use kohana 3, and I wonder: how can I catch an exception and redirect the user to another page if an exception happens:
example of code:
instead of
if ( ! $sale->loaded())
{
throw new Kohana_Request_Exception('Sale not found.');
}
I want: something like: page not found.
thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要做的是注册您自己的异常处理程序。
查看错误处理文档
What you'll need to do is register your own exception handler.
Take a look at the Error Handling documentation for an idea on what to do. Basically, you can capture any type of exception you want and do something specific with it (such as display a 404 page).