getMessage
返回一個字符串,描述拋出異常的原因。
getMessage()
方法返回導致異常被拋出的錯誤或行為的描述。
教程: PHP 異常
拋出異常,然後輸出其消息:
<?php try { throw new Exception ( "An error occurred" ) ; } catch ( Exception $e ) { echo $e -> getMessage ( ) ; } ?>
親自試一試
$exception -> getMessage ( )