JAMA
[ class tree: JAMA ] [ index: JAMA ] [ all elements ]

Source for file Error.php

Documentation is available at Error.php

  1. <?php
  2. /**
  3. * @package JAMA
  4. * 
  5. *  Error handling
  6. * @author Michael Bommarito
  7. * @version 01292005
  8. */
  9.  
  10. //Language constant
  11. define('LANG', 'EN');
  12.  
  13.  
  14. //Error type constants
  15. define('ERROR', E_USER_ERROR);
  16. define('WARNING', E_USER_WARNING);
  17. define('NOTICE', E_USER_NOTICE);
  18.  
  19. //All errors may be defined by the following format:
  20. //define('ExceptionName', N);
  21. //$error['lang'][N] = 'Error message';
  22. $error = array();
  23.  
  24. /*
  25. I've used Babelfish and a little poor knowledge of Romance/Germanic languages for the translations
  26. here.  Feel free to correct anything that looks amiss to you.
  27. */
  28.  
  29. define('PolymorphicArgumentException', -1);
  30. $error['EN'][-1] = "Invalid argument pattern for polymorphic function.";
  31. $error['FR'][-1] = "Modèle inadmissible d'argument pour la fonction polymorphe.".
  32. $error['DE'][-1] = "Unzulässiges Argumentmuster für polymorphe Funktion.";
  33.  
  34. define('ArgumentTypeException', -2);
  35. $error['EN'][-2] = "Invalid argument type.";
  36. $error['FR'][-2] = "Type inadmissible d'argument.";
  37. $error['DE'][-2] = "Unzulässige Argumentart.";
  38.  
  39. define('ArgumentBoundsException', -3);
  40. $error['EN'][-3] = "Invalid argument range.";
  41. $error['FR'][-3] = "Gamme inadmissible d'argument.";
  42. $error['DE'][-3] = "Unzulässige Argumentstrecke.";
  43.  
  44. define('MatrixDimensionException', -4);
  45. $error['EN'][-4] = "Matrix dimensions are not equal.";
  46. $error['FR'][-4] = "Les dimensions de Matrix ne sont pas égales.";
  47. $error['DE'][-4] = "Matrixmaße sind nicht gleich.";
  48.  
  49. define('PrecisionLossException', -5);
  50. $error['EN'][-5] = "Significant precision loss detected.";
  51. $error['FR'][-5] = "Perte significative de précision détectée.";
  52. $error['DE'][-5] = "Bedeutender Präzision Verlust ermittelte.";
  53.  
  54. define('MatrixSPDException', -6);
  55. $error['EN'][-6] = "Can only perform operation on symmetric positive definite matrix.";
  56. $error['FR'][-6] = "Perte significative de précision détectée.";
  57. $error['DE'][-6] = "Bedeutender Präzision Verlust ermittelte.";
  58.  
  59. define('MatrixSingularException', -7);
  60. $error['EN'][-7] = "Can only perform operation on singular matrix.";
  61.  
  62. define('MatrixRankException', -8);
  63. $error['EN'][-8] = "Can only perform operation on full-rank matrix.";
  64.  
  65. define('ArrayLengthException', -9);
  66. $error['EN'][-9] = "Array length must be a multiple of m.";
  67.  
  68. define('RowLengthException', -10);
  69. $error['EN'][-10] = "All rows must have the same length.";
  70.  
  71. /**
  72. * Custom error handler
  73. * @param int $type Error type: {ERROR, WARNING, NOTICE}
  74. * @param int $num Error number
  75. * @param string $file File in which the error occured
  76. * @param int $line Line on which the error occured
  77. */
  78. function JAMAError( $type = null, $num = null, $file = null, $line = null, $context = null ) {
  79.   global $error;
  80.   
  81.   $lang = LANG;
  82.   if( isset($type) && isset($num) && isset($file) && isset($line) )  {
  83.     switch( $type ) {
  84.       case ERROR:
  85.         echo '<div class="errror"><b>Error:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
  86.         die();
  87.         break;
  88.       
  89.       case WARNING:
  90.         echo '<div class="warning"><b>Warning:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
  91.         break;
  92.       
  93.       case NOTICE:
  94.         //echo '<div class="notice"><b>Notice:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
  95.         break;
  96.  
  97.       case E_NOTICE:
  98.         //echo '<div class="errror"><b>Notice:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
  99.         break;
  100.  
  101.       case E_STRICT:
  102.         break;
  103.         
  104.       case E_WARNING:
  105.           break;
  106.  
  107.       default:
  108.         echo "<div class=\"error\"><b>Unknown Error Type:</b> $type - $file @ L{$line}</div>";
  109.         die();
  110.         break;
  111.     }
  112.   } else {
  113.     die( "Invalid arguments to JAMAError()" );
  114.   }
  115. }
  116.  
  117. set_error_handler('JAMAError');
  118. ?>

Documentation generated on Mon, 05 Jan 2009 20:36:53 +0100 by phpDocumentor 1.4.1