I believe everything will depend on the context you are working on.
The bad side of using die
is that your execution will end there anyway. Independent of error.
Using other methods like try/catch
you will have the opportunity to work with Exception
to customize and minimize failing.
try {
$sql = $mysqli->query( "SELECT * FROM tabela" );
} catch (Exception $e) {
//$e->getMessage();
//Aqui você pode redirecionar pra outra página, exibir uma mensagem personalizada ou qualquer coisa melhor do que parar sua aplicação.
}
You can still use the two together in specific cases:
try {
$sql = $mysqli->query( "SELECT * FROM tabela" );
} catch (Exception $e) {
try {
//faça algo como segunda opção
} catch (Exception $i) {
die ('Falha: ' . $i->getMessage());
}
}
I think everything will depend on the context and how much you want to keep your user in your application.
I hope I have helped.
Font