You can try with try/catch, but I left both error_log and throw new Exception because I don't know which one you need.
try{
//code with connection
} catch (Exception $e){
error_log("This is my own message");
throw new Exception( 'Something really gone wrong', 0, $e);
}