Pan*_*ate 5 php try-catch notation
这合法吗?不在我的工作计算机附近,因此无法测试
try
someClass::someStaticFunction();
catch(Exception $e)
$e->getMessage();
Run Code Online (Sandbox Code Playgroud)
特别是缺少括号,类似于 if-else 语句
if(someBool)
someClass::someStaticFunction();
else
someClass::someOtherFunction();
Run Code Online (Sandbox Code Playgroud)
干杯!
小智 6
不,您必须使用大括号。请注意,您可以按类型捕获异常:
try {
someClass::someStaticFunction();
} catch (MyException $e) {
// do specific stuff for this exception
} catch (Exception $e) {
// do stuff for other exceptions
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5366 次 |
| 最近记录: |