Throw an exception:
<?php
try {
throw new Exception("This is an exception");
} catch(Exception $e) {
echo $e->getMessage();
}
?>
Try it Yourself »
The throw
keyword is used to throw exceptions. Exceptions are a way to change the program flow if an unexpected situation arises, such as invalid data.
The try...catch...finally
structure can be used to handle exceptions.
The try
keyword.
The catch
keyword.
The finally
keyword.
Read more about try..catch.finally (Exceptions) in our PHP Exceptions Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!