如上。请熟悉的大神帮忙解释一下,php语言里面,try catch语句中如果有return,执行顺序是什么?
上面这段代码,想要的是:pdo事物正常运行返回true,若有异常返回false,请问能否正常实现?
回复讨论(解决方案) 你这样写的就是:正常运行返回true,若有异常返回false
但一定要设置属性项 pdo::attr_errmode 为 pdo::errmode_exception
否则异常处理无效
还有
exception $e
要写作
pdoexception $e
毛病还不少哦
版主大大已经回答了,我来混分的,一个小例子
$res=test('oo'); if($res){ echo '呵呵'; } function test($name){ try{ a($name); return true; }catch (exception $e){ echo $e->getmessage(); return false; } } function a($name){ if($name==xx){ return true; }else{ throw new exception(error); } }
你这样写的就是:正常运行返回true,若有异常返回false
但一定要设置属性项 pdo::attr_errmode 为 pdo::errmode_exception
否则异常处理无效
还有
exception $e
要写作
pdoexception $e
毛病还不少哦
感谢!