简体   繁体   中英

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(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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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