Yaf_Exception是Yaf使用的异常类型, 它继承自Exception, 并实现了异常链.
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception
![]() |
注意 |
|---|---|
| 只有在yaf.throw_exception(php.ini)或者yaf.throwException(配置文件)开启的情况下, Yaf才会抛出异常, 否则Yaf在出错的时候将trigger_error, 这种情况下, 可以使用Yaf_Dispatcher::setErrorHandler来捕获错误. |
Yaf_Exception {protected stringmessage;protected stringcode;private Exception_previous;public void __construct ( string $message ,
int $code = 0 ,
Exception $previous = NULL );final public string Exception::getMessage ( void );final public int Exception::getCode ( void );public final Exception getPrevious ( void );final public string Exception::getFile ( void );final public int Exception::getLine ( void );
}
继承自Yaf_Exception, 在Yaf启动失败的时候抛出.
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\StartupError
Yaf_Exception_StartupError extends Yaf_Exception {protected stringcode= YAF_ERR_STARTUP_FAILED ;
}
继承自Yaf_Exception, 在路由失败的时候抛出.
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\RouterFailed
Yaf_Exception_RouterFailed extends Yaf_Exception {protected stringcode= YAF_ERR_ROUTER_FAILED ;
}
继承自Yaf_Exception, 在分发失败的时候抛出.
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\DispatchFailed
Yaf_Exception_DispatchFailed extends Yaf_Exception {protected stringcode= YAF_ERR_DISPATCH_FAILED ;
}
继承自Yaf_Exception, 在加载需要类失败的时候抛出.
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\LoadFailed
Yaf_Exception_LoadFailed extends Yaf_Exception {protected stringcode= YAF_ERR_AUTOLOAD_FAILED ;
}
继承自Yaf_Exception_LoadFailed, 在找不到路由指定的模块时抛出
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\LoadFailed\Module
Yaf_Exception_LoadFailed_Module extends Yaf_Exception_LoadFailed {protected stringcode= YAF_ERR_NOTFOUND_MODULE ;
}
继承自Yaf_Exception_LoadFailed, 在找不到路由指定的控制器时抛出
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\LoadFailed\Controller
Yaf_Exception_LoadFailed_Controller extends Yaf_Exception_LoadFailed {protected stringcode= YAF_ERR_NOTFOUND_CONTROLLER ;
}
继承自Yaf_Exception_LoadFailed, 在找不到路由指定的动作时抛出
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\LoadFailed\Action
Yaf_Exception_LoadFailed_Action extends Yaf_Exception_LoadFailed {protected stringcode= YAF_ERR_NOTFOUND_ACTION ;
}
继承自Yaf_Exception_LoadFailed, 在找不到指定的视图模板文件时抛出
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\LoadFailed\View
Yaf_Exception_LoadFailed_View extends Yaf_Exception_LoadFailed {protected stringcode= YAF_ERR_NOTFOUND_VIEW ;
}
继承自Yaf_Exception, 在关键逻辑参数出错的时候抛出
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Exception\TypeError
Yaf_Exception_TypeError extends Yaf_Exception {protected stringcode= YAF_ERR_TYPE_ERROR ;
}
Yaf 抛出的每个异常都带有一个用于标识故障类型的错误码, 可以通过 getCode() 获取。各异常类对应的错误码如下:
表 11.1. Yaf 异常错误码
| 异常类 | 错误码 | 触发时机 |
|---|---|---|
| Yaf_Exception_StartupError | 512 | 应用启动失败, 即在路由开始之前, Yaf_Application 初始化期间发生错误 |
| Yaf_Exception_RouterFailed | 513 | 路由失败, 例如没有任何已注册的路由能匹配到来的请求 |
| Yaf_Exception_DispatchFailed | 514 | 分发器无法把已路由的请求分发到控制器动作(例如 forward 链式转发次数超出 yaf.forward_limit) |
| Yaf_Exception_LoadFailed_Module | 515 | 请求的模块无法被找到或加载 |
| Yaf_Exception_LoadFailed_Controller | 516 | 请求的控制器无法被找到或加载 |
| Yaf_Exception_LoadFailed_Action | 517 | 请求的动作无法被找到或加载 |
| Yaf_Exception_LoadFailed_View | 518 | 请求的视图(模板)脚本无法被找到或加载 |
| Yaf_Exception_LoadFailed | 520 | 自动加载器无法加载所需的脚本, 更具体的失败由它的子类表示 |
| Yaf_Exception_TypeError | 521 | 传递给 Yaf 方法的参数类型不符合预期或值无效 |
![]() |
注意 |
|---|---|
| 当加载了 SPL 扩展时, Yaf_Exception 继承自 RuntimeException, 否则继承内置的 Exception。在打开 yaf.use_namespace 的情况下, 也可以使用命名空间风格的类名, 例如 Yaf\Exception\StartupError。 |