Welcome Guest, Not a member yet? Register   Sign In
Catch exeption from database insert
#1
Exclamation 

Developing a web application, I'm using insert () to add registers to the database.  I'm using the optional parameter to return a boolean value so I can check if it succeeded.

The problem is that if I try to insert a new register with a yet existing key CodeIgniter catch the exception and shows the tracing information.  So I added a try..catch but it doesn't catch anything.

The code I use is:

PHP Code:
try
{
  $Result $this->insert ($Datafalse);
}
catch (\
Exception $Error)
{
  log_message ('error'$Error->getMessage ());
  $Result false;


I've tried several exception classes (including CodeIgniter\Database\Exception\DatabaseException) but nothing works, neither debug mode nor production mode: CI overrides my code.  finally does work though.

Why is CI overriding my try..catch blocks and how can I prevent it?

P.S: I've search both in forums and in the Internet but I've found only old threads (CI3 or CI2) or unrelated with my problem.

P.S.2: If you'll say that I should check data before insert (as I've read in some old threads), I shouldn't:  I want the database to check data integrity and just check if it succeeded.  That's why relational databases were invented for, aren't they?
Reply


Messages In This Thread
Catch exeption from database insert - by Ñuño Martínez - 06-27-2024, 03:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB