2

我已经看过这篇文章中的代码示例,但是 throwingController_Exception_404会产生错误。

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

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

4

1 回答 1

2

我认为你想要的例外是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;

我不知道“官方”最佳实践是什么,但这是我通过玩耍发现的。

于 2010-04-16T12:55:11.107 回答