PHP
最近はwith CodeIgniter
Frameworkを学んでいます。私は例外処理に取り組んでいますが、例外処理が設定db_debug = TRUE
されている場合にデータベースエラーで機能しないことに驚いたことがありdatabase.php
ます。
の場合db_debug = FALSE
、エラーをスローしてキャッチできますが、 の場合TRUE
、データベース エラーのあるページを直接表示します。
これが私のコードです:
でModel
:
$this->db->insert('tbl_name',$data);
if (strpos($this->db->_error_message(),'constraint_name') !== FALSE)
{
throw new UniqueConstraintException($this->db->_error_message()); // UniqueConstraintException is customized excpetion
}
でController
:
try
{
//calling the method from model having above code
}
catch(UniqueConstraintException $ex)
{
echo "There is already item with same item name";
}
catch(Exception $ex)
{
echo $ex->getMessage();
}
設定があってもデータベースエラー時の例外処理を実装することはできdb_debug = TRUE
ますか?