【问题标题】:What sort of exceptions should I be throwing from inside Kohana 3?我应该从 Kohana 3 内部抛出什么样的异常?
【发布时间】:2010-04-16 05:09:09
【问题描述】:

我在this article 上看过代码示例,但是抛出Controller_Exception_404 会产生错误。

我刚刚抛出了普通的异常。我记得在 Kohana 2.3 中,您可以根据情况抛出不同的。

有没有人列出什么时候应该抛出什么异常?

【问题讨论】:

    标签: php exception kohana kohana-3


    【解决方案1】:

    我认为你想要的例外是Kohana_Request_Exception。以下是 Kohana 定义的所有异常的列表(使用 grep -iR "class .*Exception" . 生成):

    class Validate_Exception extends Kohana_Validate_Exception {}
    class Kohana_Validate_Exception extends Kohana_Exception {
    class Kohana_Request_Exception extends Kohana_Exception {  }
    class Kohana_Exception extends Exception {
    class Kohana_View_Exception extends Kohana_Exception {  }
    

    如果您想要 404 响应代码,我认为您还必须在控制器中执行此操作

    $this->request->status = 404;
    

    我不知道“官方”最佳做法是什么,但这是我通过玩弄后发现的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      • 2010-11-18
      • 2015-05-12
      • 1970-01-01
      • 2011-05-06
      • 2013-05-20
      • 1970-01-01
      相关资源
      最近更新 更多