1.throw
throw 表达式;
2.try-catch
try {
//可能异常的代码
} catch (Exception $e) {
//异常时要做什么
}
3.try-finally
try {
//可能异常的代码
} finally {
//无论是否异常,始终运行
}
4.try-catch-finally
如果在 try
或 catch
块中包含 return
语句,finally
块仍将执行,但是,return
语句的返回值将在 finally
块执行后返回。如果在 finally
块中也包含 return
语句,则返回 finally
块中 return
语句的返回值,而不会返回 try
或 catch
块中的 return
语句的返回值。
try {
//可能异常的代码
} catch (Exception $e) {
//异常时要做什么
} finally {
//无论是否异常,始终运行
}
原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/php/phplang/28883.html