![]() |
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 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?
Try \Throwable $e
It works. Thank you.
I'm still not used to the new* Trowable hierarchy. I still think the base class is Exception. _________________________ * I know it's not new-new.
In my opinion, it should be DatabaseException.
What database driver do you use?
MySQLi, but the idea is that the customer can use any one available.
(06-28-2024, 01:20 AM)Ñuño Martínez Wrote: It works. Thank you. Throwable is more general than Exception in PHP. It has been around since PHP 7, so it is not new. Throwable is the base interface for any object that can be thrown via a throw statement, including Error and Exception. from https://www.php.net/manual/en/class.throwable.php
And catching large class like Throwable is not good practice.
Because it catches all exceptions including others than you want to catch.
Code: This may shed some light on the subject. StackOverflow - Catch does not report an error when mysqli INSERT fails. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(07-09-2024, 09:58 PM)InsiteFX Wrote: Thank you. That's what I was looking foor but I didn't found. |
Welcome Guest, Not a member yet? Register Sign In |