Welcome Guest, Not a member yet? Register   Sign In
Fatal Errors when DataBase command fails
#5

(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")
http://prntscr.com/pl9oub

And here is the code I'm running:

Code:
public function addAudio($name, $path){

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

$db->transStart();

$data = [
'name' => $name,
'path' => $path
];
echo "Hello world 1!!\n";
$builder_audio->insert($data);
echo "Hello world 2!!\n";
if(!$db->affectedRows()){
$flag = false;
return $flag;
}

$db->transComplete();
return $flag;
}catch(FormatException $ex){
var_dump($ex);
die;
}

}
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB