• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fatal Errors when DataBase command fails

(10-18-2019, 01:41 PM)kilishan Wrote: Instead of checking for the number of affected rows, catch the Exception that's being thrown. You can handle the same situation you're trying now within the catch block.

I was already using an Try Catch when I call this function (it is inside a Modal). But I tried to make the Try Catch just around the Insert method or all the my $db function but it didn't prevent the request from being shut down and return status 500 to my browser.
I tried catch(Exception $ex){... and catch(FormatException $ex){

Here is what is happening to the request: (repair the echo "Hello World 1!!\n" and echo "Hello world 2!!\n")

And here is the code I'm running:

public function addAudio($name, $path){

$db = \Config\Database::connect();
$builder_audio = $db->table('audios');
$flag = true;


$data = [
'name' => $name,
'path' => $path
echo "Hello world 1!!\n";
echo "Hello world 2!!\n";
$flag = false;
return $flag;

return $flag;
}catch(FormatException $ex){


Messages In This Thread
RE: Fatal Errors when DataBase command fails - by GuilhermeBiz - 10-18-2019, 02:04 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.