如何使用PHP基础异常捕获zend框架2中的异常?
如果行未注释,则找不到异常类,并且未捕获异常。
如果行被注释,则命名空间为空,并且创建PHP基异常类。
我不能取消注释这一行,因为zend在很多地方都需要它,i.g。ActionController。
如何做到这一点?
我必须只使用Zend异常吗?我必须使用哪个,更通用的zend异常类是什么?
<?php namespace SecureDraw; ?> // <<----- If remove this line catch work ok!!
<?php echo $this->doctype(); ?>
<?php
use Zend\Db\Adapter\Adapter as DbAdapter;
try{
$dbAdapter = new DbAdapter(array(
'driver' => 'Pdo_Mysql',
'database' => 'securedraw',
'username' => 'root',
'password' => '',
));
$sql = "select * from tablenotexist";
$statement = $dbAdapter->createStatement($sql);
$sqlResult = $statement->execute();
}
catch(Exception $e){
echo "hello";
}
?>发布于 2012-10-29 07:18:07
您需要添加:
use Exception;或使用:
catch (\Exception $e) {所有内置的PHP类都存在于根(\)名称空间中。您的示例中的try-catch尝试匹配SecureDraw\Exception。
https://stackoverflow.com/questions/13113942
复制相似问题