我试图弄清楚在PHP中处理错误是否有一个好的或更好的方法,而不是我在下面做的.如果电话有问题,我想抛出异常parse_ini_file.这有效,但是有更优雅的方法来处理错误吗?
public static function loadConfig($file, $type)
{
if (!file_exists($file))
{
require_once 'Asra/Core/Exception.php';
throw new Asra_Core_Exception("{$type} file was not present at specified location: {$file}");
}
// -- clear the error
self::$__error = null;
// -- set the error handler function temporarily
set_error_handler(array('Asra_Core_Loader', '__loadConfigError'));
// -- do the parse
$parse = parse_ini_file($file, true);
// -- restore handler
restore_error_handler();
if (!is_array($parse) || is_null($parse) || !is_null(self::$__error))
{
require_once 'Asra/Core/Exception.php';
throw new Asra_Core_Exception("{$type} file at {$file} appears to be
}
}
Run Code Online (Sandbox Code Playgroud)
__ loadConfigError …