Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> łapanie wyjątków a połączenie MySql
Gligamesh
post
Post #1





Grupa: Zarejestrowani
Postów: 227
Pomógł: 0
Dołączył: 13.06.2003
Skąd: rykowice

Ostrzeżenie: (0%)
-----


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ć ?


  1. $errors = array(
  2. 'error' => array(),
  3. 'warning' => array(),
  4. 'notice' => array());
  5.  
  6. class Error extends Exception
  7. {
  8. protected $level = 'error';
  9. function getLevel()
  10. {
  11. return $this->level;
  12. }
  13. }
  14.  
  15. class Warning extends Error
  16. {
  17. protected $level = 'warning';
  18. }
  19.  
  20. class Notice extends Error
  21. {
  22. protected $level = 'notice';
  23. }
  24.  
  25. function msg($e)
  26. {
  27. global $errors;
  28. $errors[$e->getLevel()][] = (String)$e;
  29. if($e->getLevel() == 'error') {
  30. $tpl = New Template();
  31. $tpl -> assign('e', $e->getMessage());
  32. $tpl -> display('przyklad_bledy.php');
  33. die();
  34. } elseif($e->getLevel() == 'notice') {
  35. // echo $e->getLine().' -> '.$e->getMessage();
  36. }
  37. }
  38.  
  39. function exception_handler($e)
  40. {
  41. msg($e);
  42. }
  43.  
  44. function error_handler($no, $str, $file, $line)
  45. {
  46. if(production_mode === true) {
  47. $msgContent = 'Napotkano błąd aplikacji, numer błędu: '.$no;
  48. } else {
  49. $msgContent = $no.' '.$str.' @ '.$file.' # '.$line;
  50. }
  51.  
  52. msg(new Error($msgContent));
  53. }
  54.  
  55. set_exception_handler('exception_handler');
  56. set_error_handler('error_handler');
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 10:57