【发布时间】:2014-02-05 21:19:01
【问题描述】:
我目前正在尝试在 Laravel 中捕获 PDOException,并允许我的应用程序在捕获错误后继续运行。我在不同的位置尝试了多次尝试捕获,但在导致应用失败之前我无法捕获错误。
这是我的模型:
class Oracle extends Eloquent {
protected $connection = 'oracle';
protected $user = '';
protected $table = '';
public $timestamps = false;
public function __construct(array $attributes = array()) {
parent::__construct($attributes);
DB::reconnect('oracle');
$this->table = Config::get('database.connections.oracle.table');
$this->user = Config::get('database.connections.oracle.username');
}
public function scopegetPerms($callback, $db) {
return $callback->select('*')->where('grantee', '=', strtoupper(trim($this->user)))->orderBy('granted_role');
}
}
我正在即时更新oracle 连接设置,并使用DB::reconnect 函数获取更改。一切都按预期工作。我希望能够捕获无效的用户/密码异常,并在以后继续通知用户。但我试图捕捉异常并没有奏效。
我尝试在 DB::reconnect() 和查询本身周围放置一个 try/catch。
这是我得到的错误:
{"error":{"type":"PDOException","message":"ORA-01017: invalid username\/password; logon denied"
【问题讨论】: