php - 更好的错误处理方式?

标签 php class error-handling

错误处理的最佳方式是什么?这是我想出的:

class test {

    public static function Payment($orderid, $total) {
        if (empty($orderid) && empty($total)) {
            return array('status' => 'fail', 'error' => 'Missing Data');
        }
    }

}

我听说过 Try/Exceptions,但如何将它应用到我的代码中?如果您能提供示例,那就太好了!

最佳答案

如果你使用 PHP 5,你可以用异常处理错误:

http://fr2.php.net/manual/en/class.exception.php

这种方式比手动设置异常消息更干净,因为您可以访问 try catch 系统并且可以隔离异常处理

关于php - 更好的错误处理方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5967153/

相关文章:

php - PHP 中是否有不使用 cURL 的更简单的 HTTP POST?

带有模板编译错误的 C++ 类

python - 在不更改名称的情况下向父类方法添加额外功能

javascript - 当我的 Controller 执行功能时显示加载图像

php - htmlspecialchars() 应该用于输入信息还是输出之前?

c++ - 如何制作包含 "Private"?

Android 应用程序无法启动 noClassDefFoundError

r - R-交叉验证错误处理- “dims product do not match the length of object”

powershell - 在Powershell中,我可以确定是否通过-ErrorAction SilentlyContinue调用了我的函数吗?

php - AFNetworking 将 UIImage 上传为 NSData -> PHP 脚本移动文件