I would like to handle the error that occurs if the MySQL server is not running, I want only one message to appear so I made the following code:
function mensagemErro () {
throw new \Exception("Error connecting to database");
}
function connect() {
try {
$pdo = new \PDO("mysql:host=localhost;dbname=DB;charset=utf8", 'root', 'root');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
return $pdo;
} catch (Exception $e) {
mensagemErro();
echo $e->getMessage();
}
}
However, the custom message is not appearing, only the Fatal Error: < path of the .php file > online 11 And I do not want the file name and error line to appear, just the message.