I'm new to try and catch in PHP. When I tried it I expected all the warnings and errors in the $e
variable. They are logged in $e
but also output on the screen.
My current solution for it is to add @
before $db
to prevent the warnings from popping up on the screen. Is there a better solution? Mine feels a little hacky.
<?php
function db() {
$db = array();
try {
@$db = new Database(array(
'type' => 'mysql',
'host' => 'localhosts',
'database' => 'megastore',
'user' => 'root',
'password' => ''
));
} catch (Exception $e) {
echo $e;
}
return $db;
}