简体   繁体   English

PHP try-catch支持短符号?

[英]PHP try-catch supports short notation?

Is this legal? 这合法吗? Not near my work computer so can't test 不靠近我的工作电脑所以无法测试

try
    someClass::someStaticFunction();
catch(Exception $e)
    $e->getMessage();

Specifically the lack of brackets, similar to an if-else statement 特别是缺少括号,类似于if-else语句

if(someBool)
    someClass::someStaticFunction();
else
    someClass::someOtherFunction(); 

Cheers! 干杯!

No you must use the brace brackets. 不,你必须使用支架。 Note that you can catch exceptions by type : 请注意,您可以按类型捕获异常:

try {
  someClass::someStaticFunction();
} catch (MyException $e) {
  // do specific stuff for this exception
} catch (Exception $e) {
  // do stuff for other exceptions
}

No, doesn't seem like it works. 不,似乎不起作用。

Check my example here: http://codepad.org/BpSBiPDY 在这里查看我的示例: http//codepad.org/BpSBiPDY

不,它没有,没有替代语法的try / catch ...它只有8个字符加上Exception $ e ...这不是很长

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM