use*_*378 4 php error-handling class
什么是错误处理的最佳方法?这就是我想出的:
class test {
public static function Payment($orderid, $total) {
if (empty($orderid) && empty($total)) {
return array('status' => 'fail', 'error' => 'Missing Data');
}
}
}
Run Code Online (Sandbox Code Playgroud)
我听说过Try/Exceptions但是如何将其融入我的代码中?如果你能提供一个很棒的例子!
如果使用PHP 5,则可以处理异常错误:
http://fr2.php.net/manual/en/class.exception.php
这种方式比手动设置异常消息更清晰,因为您可以访问try catch系统,并且可以隔离异常处理