Witajcie, poniżej wklejam to co stworzyłem sobie od obsługi błędów i komunikatów (jeszcze nie skończone). Pojawił się spory problem z MySql, chodzi mi o błąd połączenia, proste pytanie jak go złapać ?
class Error extends Exception
{
protected $level = 'error';
function getLevel()
{
return $this->level;
}
}
class Warning extends Error
{
protected $level = 'warning';
}
class Notice extends Error
{
protected $level = 'notice';
}
function msg($e)
{
$errors[$e->getLevel()][] = (String)$e;
if($e->getLevel() == 'error') {
$tpl = New Template();
$tpl -> assign('e', $e->getMessage());
$tpl -> display('przyklad_bledy.php');
} elseif($e->getLevel() == 'notice') {
// echo $e->getLine().' -> '.$e->getMessage();
}
}
function exception_handler($e)
{
msg($e);
}
function error_handler($no, $str, $file, $line)
{
if(production_mode === true) {
$msgContent = 'Napotkano błąd aplikacji, numer błędu: '.$no;
} else {
$msgContent = $no.' '.$str.' @ '.$file.' # '.$line;
}
msg(new Error($msgContent));
}
set_exception_handler('exception_handler');