[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 /** 4 * \defgroup Core 5 */ 6 7 /** 8 * \ingroup Core 9 * 10 * PHP Java-style definition of an Exception object. 11 */ 12 class Exception 13 { 14 15 var $_exceptionString; 16 var $_exceptionCode; 17 18 /** 19 * Creates a new Exception. 20 * 21 * @param exceptionString Descriptive message carried by the exception 22 * @param exceptionCode Numerical error code assigned to this exception 23 */ 24 function Exception( $exceptionString, $exceptionCode = 0 ) 25 { 26 27 28 $this->_exceptionString = $exceptionString; 29 $this->_exceptionCode = $exceptionCode; 30 } 31 32 /** 33 * Throws the exception and stops the execution, dumping some 34 * interesting information. 35 */ 36 function throw() 37 { 38 // gather some information 39 print( "<br/><b>Exception message</b>: ".$this->_exceptionString."<br/><b>Error code</b>: ".$this->_exceptionCode."<br/>" ); 40 $this->_printStackTrace(); 41 } 42 43 function _printStackTrace() 44 { 45 if( function_exists("debug_backtrace")) { 46 $info = debug_backtrace(); 47 48 print( "-- Backtrace --<br/><i>" ); 49 foreach( $info as $trace ) { 50 if( ($trace["function"] != "_internalerrorhandler") && ($trace["file"] != __FILE__ )) { 51 print( $trace["file"] ); 52 print( "(".$trace["line"]."): " ); 53 if( isset( $trace["class"] )) { 54 if( $trace["class"] != "" ) 55 print( $trace["class"]."." ); 56 } 57 print( $trace["function"] ); 58 print( "<br/>" ); 59 } 60 } 61 print( "</i>" ); 62 } 63 else { 64 print("<i>Stack trace is not available</i><br/>"); 65 } 66 } 67 } 68 69 /** 70 * This error handler takes care of throwing exceptions whenever an error 71 * occurs. 72 */ 73 function _internalErrorHandler( $errorCode, $errorString ) 74 { 75 $exc = new Exception( $errorString, $errorCode ); 76 77 //print(var_dump(debug_backtrace())); 78 79 // we don't want the E_NOTICE errors to throw an exception... 80 if( $errorCode != E_NOTICE ) 81 $exc->throw(); 82 } 83 84 /** 85 * Throws an exception 86 */ 87 function throw( $exception ) 88 { 89 $exception->throw(); 90 } 91 92 function catch( $exception ) 93 { 94 print( "Exception catched!" ); 95 } 96 97 // this registers our own error handler 98 $old_error_handler = set_error_handler( "_internalErrorHandler" ); 99 // and now we say what we would like to see 100 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |