com.lokorin.lokorin.lib
[ class tree: com.lokorin.lokorin.lib ] [ index: com.lokorin.lokorin.lib ] [ all elements ]

Source for file lib_errors.php

Documentation is available at lib_errors.php

  1. <?php
  2. /*
  3. * Lokorin.com
  4. * Copyright 2004-2006
  5. * Licensed under the GNU LGPL. See COPYING for full terms.
  6. */
  7. /**
  8. * A library that contains everything that is connected to errors.
  9. * @author Andreas Launila
  10. * @version $Revision: 1.10 $
  11. * @package com.lokorin.lokorin.lib
  12. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  13. */
  14.  
  15. /**
  16. * For access to common constants and functions.
  17. */
  18. require_once('common.php');
  19.  
  20. /**
  21. * Inserts and error into the error table in the database.
  22. * @param string $message The error message.
  23. * @param string $url The URL where the error occured, the current url is
  24. * used by default.
  25. * @access public
  26. */
  27. function insertError($message, $url='') {
  28. global $db;
  29.  
  30. if(DEBUG_MODE_ON) {
  31. echo '<b>'.htmlspecialchars($message).'</b>';
  32. }
  33. if($url == '') {
  34. doInclude('lib_util');
  35. $url = getCurrentUrl();
  36. }
  37. $vars = array(
  38. 'message' => $message,
  39. 'url' => $url,
  40. 'ip' => $_SERVER['REMOTE_ADDR'],
  41. 'browser' => $_SERVER['HTTP_USER_AGENT'],
  42. 'timestamp' => time());
  43.  
  44. $db->queryInsert(TABLE_ERRORS, $vars);
  45. }
  46.  
  47.  
  48. /**
  49. * Logs an exception, providing information about the current state. The script
  50. * then continues on.
  51. * @param string $exception The exception that should be logged.
  52. * @access public
  53. */
  54. function logException(Exception $exception) {
  55. insertError('Exception: [File: '.$exception->getFile().', Line: '.
  56. $exception->getLine().', Message: '.$exception->getMessage().']');
  57. }
  58.  
  59. /**
  60. * Logs a fatal exception, providing information about the current state.
  61. * The exception is fatal so the script immidiatly dies after logging it.
  62. * @param string $exception The exception that should be logged.
  63. * @access public
  64. */
  65. function logFatalException(Exception $exception) {
  66. insertError('Exception: [File: '.$exception->getFile().', Line: '.
  67. $exception->getLine().', Message: '.$exception->getMessage().']');
  68. die('A fatal error has been detected, the error has been logged and the '.
  69. 'webmaster will be notified. Sorry for any inconvenience this ' .
  70. 'error may have caused you.');
  71. }
  72.  
  73. /**
  74. * An exception used when an element that was searched for could not be found.
  75. * @author Andreas Launila
  76. * @package com.lokorin.lokorin.lib
  77. */
  78. class NoSuchElementException extends Exception {}
  79.  
  80. /**
  81. * An exception used when an error occurs while performing an IO operation.
  82. * @author Andreas Launila
  83. * @package com.lokorin.lokorin.lib
  84. */
  85. class IOException extends Exception {}
  86.  
  87. /**
  88. * An exception used when an error occurs while performing an IO operation
  89. * because of that a file was not found.
  90. * @author Andreas Launila
  91. * @package com.lokorin.lokorin.lib
  92. */
  93. class FileNotFoundException extends IOException {}
  94.  
  95. /**
  96. * An exception used when an error occurs as a result of invalid input
  97. * arguments to a function.
  98. * @author Andreas Launila
  99. * @package com.lokorin.lokorin.lib
  100. */
  101. class IllegalArgumentException extends Exception {}
  102.  
  103. /**
  104. * An exception used when an error occurs as a result of invalid state.
  105. * @author Andreas Launila
  106. * @package com.lokorin.lokorin.lib
  107. */
  108. class IllegalStateException extends Exception {}
  109.  
  110. /**
  111. * An exception used when an error occurs as a result of an invalid url being
  112. * requested.
  113. * @author Andreas Launila
  114. * @package com.lokorin.lokorin.lib
  115. */
  116. class UrlNotFoundException extends Exception {}
  117.  
  118. ?>

Documentation generated on Sun, 16 Apr 2006 21:03:21 +0200 by phpDocumentor 1.3.0RC4