Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Błąd z obsługą błędów
daw22
post
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 1
Dołączył: 1.09.2007

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


  1. <?php
  2. class Wyjatek
  3. {
  4. function __construct(string $message = NULL, int $code = NULL)
  5. {
  6. {
  7. $this->message = $message;
  8. }
  9. $this->code = $code;
  10. $this->file = __FILE__;
  11. $this->line = __LINE__;
  12. $this->trace = debug_backtrace();
  13. $this->string = StringFormat($this);
  14. }
  15.  
  16. protected $message = 'Nieznany błąd krytyczny';
  17. protected $code = 0;
  18. protected $file;
  19. protected $line;
  20.  
  21. private $trace;
  22. private $string;
  23.  
  24. final function getMessage()
  25. {
  26. return $this->message;
  27. }
  28. final function getCode()
  29. {
  30. return $this->code;
  31. }
  32. final function getFile()
  33. {
  34. return $this->file;
  35. }
  36. final function getLine()
  37. {
  38. return $this->line;
  39. }
  40. final function getTrace()
  41. {
  42. return $this->trace;
  43. }
  44. final function getTraceAsString()
  45. {
  46. return self::TraceFormat($this);
  47. }
  48. function __toString()
  49. {
  50. return '<table>
  51. <tr>
  52. <td><strong>' . $this->getCode() . '</strong>: ' . $this->getMessage() . '<br /></td>
  53. <td>Nastąpił w pliku ' . $this->getFile(). ' w lini ' . $this->getLine() . '</td></tr></table>';
  54.  
  55. }
  56. static private function StringFormat(Exception $exception)
  57. {
  58. //
  59. //
  60. }
  61. static private function TraceFormat(Exception $exception)
  62. {
  63. //
  64. //
  65. }
  66. }
  67. try
  68. {
  69. throw new Wyjatek('Wystąpił błąd krytyczny', 2);
  70. }
  71. catch(Wyjatek $ee)
  72. {
  73. echo $ee;
  74. }
  75. ?>


Powoduje to Fatalny Błąd:
Kod
[b]Fatal error[/b]: Argument 1 passed to Wyjatek::__construct() must be an object of class string, called in D:\WebServer\httpd\index.php on line 168 and defined in [b]D:\WebServer\httpd\index.php[/b] on line [b]91

[/b]Liniami kodu proszę się nie przejmować, wszystko jest zaznaczone jako komenatrze. Nie wiem dlaczego tak się dzieje [chodzi o błąd].
Proszę o pomoc w tej kwestii z góry pięknie dziękuję.
Pozdrowionka
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: 21.08.2025 - 21:07