getCode
返回異常代碼。
getCode()
方法返回一個整數,該整數可用於識別異常。
教程: PHP 異常
拋出一個異常,並輸出其代碼:
<?php try { throw new Exception ( "An error occurred" , 120 ) ; } catch ( Exception $e ) { echo "Error code: " . $e -> getCode ( ) ; } ?>
親自試一試
$exception -> getCode ( )