Zac*_*own 5 php python exception try-catch
我是一个强大的Python程序员,但在PHP方面并不完全.我需要尝试一些东西,如果不能解决问题,那就做点别的了.
这就是Python中的样子:
try:
print "stuf"
except:
print "something else"
Run Code Online (Sandbox Code Playgroud)
这在PHP中会是什么?
http://php.net/manual/en/language.exceptions.php
try {
print 'stuff';
} catch (Exception $e) {
var_dump($e);
}
Run Code Online (Sandbox Code Playgroud)
注意:这仅适用于异常,而不适用于错误.
请参阅http://www.php.net/manual/en/function.set-error-handler.php.
try {
// do stuff ...
} catch (Exception $e) {
print($e->getMessage());
}
Run Code Online (Sandbox Code Playgroud)
请参见http://php.net/manual/en/language.exceptions.php