I have this code where I absorb mysqli_sql_exception, log it and throw a new exception with a more generic error message that can be displayed to the user. However the new exception is not being caught by the second catch.
try {
$query = "Use any invalid query here";
mysqli_query($connect, $query);
} catch (mysqli_sql_exception $e){
writeToLog("Failed to update in Line 301. Error: ".$e->getMessage()."nQuery: $query");
throw new Exception("Failed to cancel booking. Please try again or contact support."); // <-- error source
} catch (Exception $e) {
$_SESSION['msg'] = ['type' => 'warning', 'content' => $e->getMessage()];
}
I get this error
Fatal error: Uncaught Exception: Failed to cancel booking. Please try again or contact support.
There are no namespaces being used in this file and I’ve tried all combinations of backslashes. What am I doing wrong?