<?php //创建可抛出一个异常的函数 function checkNum($number) { if($number>1) { throw new Exception("Value must be 1 or below"); } return true; } checkNum(2); ?>
Fatal error: Uncaught exception ‘Exception’ with message ‘Value must be 1 or below’ in G:/phpStudy/Public/zititest.php:7 Stack trace: #0 G:/phpStudy/WWW/mircoweb/mircoweb/wwwroot/Public/zititest.php(12): checkNum(2) #1 {main} thrown in G:/phpStudy/WWW/mircoweb/mircoweb/wwwroot/Public/zititest.php on line 7
<?php //创建可抛出一个异常的函数 function checkNum($number) { if($number>1) { throw new Exception("Value must be 111 or below"); } return true; } //在 "try" 代码块中触发异常 try { checkNum(2); //If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below'; } //捕获异常 catch(Exception $e) { echo 'Message: ' .$e->getMessage(); } ?>
Message: Value must be 111 or below
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19019.html