
异常是程序执行过程中出现的问题。在程序执行过程中,发生异常时,该语句后面的代码将不会被执行,PHP 将尝试查找第一个匹配的 catch 块。如果未捕获异常,则会发出 PHP 致命错误,并显示“未捕获异常”。
基于Intranet/Internet 的Web下的办公自动化系统,采用了当今最先进的PHP技术,是综合大量用户的需求,经过充分的用户论证的基础上开发出来的,独特的即时信息、短信、电子邮件系统、完善的工作流、数据库安全备份等功能使得信息在企业内部传递效率极大提高,信息传递过程中耗费降到最低。办公人员得以从繁杂的日常办公事务处理中解放出来,参与更多的富于思考性和创造性的工作。系统力求突出体系结构简明
0
try {
print "this is our try block";
throw new Exception();
}catch (Exception $e) {
print "something went wrong, caught yah! n";
}finally {
print "this part is always executed";
}<?php
function printdata($data) {
try {
//If var is six then only if will be executed
if($data == 6) {
// If var is zero then only exception is thrown
throw new Exception('Number is six.');
echo "</p><p> After throw (It will never be executed)";
}
}
// When Exception has been thrown by try block
catch(Exception $e){
echo "</p><p> Exception Caught", $e->getMessage();
}
//this block code will always executed.
finally{
echo "</p><p> Final block will be always executed";
}
}
// Exception will not be rised here
printdata(0);
// Exception will be rised
printdata(6);
?>Final block will be always executed Exception CaughtNumber is six. Final block will be always executed
要处理异常,程序代码必须位于 try 块内。每次尝试必须至少有一个相应的 catch 块。多个catch块可用于捕获不同类别的异常。
以上就是PHP中的异常处理是什么?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号