(PECL rar >= 2.0.0)
RarException::setUsingExceptions — 激活和禁用使用异常进行错误处理
当且仅当参数为true时,当 UnRAR 库遇到错误时,将抛出类型为RarException的异常,而不是发出警告并返回一个表示错误的特殊值。
对于以下库外部发生的错误,也将抛出异常(其错误代码将为 -1)
不返回值。
示例 #1 RarException::setUsingExceptions() 示例
<?php
var_dump(RarException::isUsingExceptions());
$arch = RarArchive::open("does_not_exist.rar");
var_dump($arch);
RarException::setUsingExceptions(true);
var_dump(RarException::isUsingExceptions());
$arch = RarArchive::open("does_not_exist.rar");
var_dump($arch); //未到达
?>以上示例将输出类似以下内容
bool(false)
Warning: RarArchive::open(): Failed to open does_not_exist.rar: ERAR_EOPEN (file open error) in C:\php_rar\trunk\tests\test.php on line 3
bool(false)
bool(true)
Fatal error: Uncaught exception 'RarException' with message 'unRAR internal error: Failed to open does_not_exist.rar: ERAR_EOPEN (file open error)' in C:\php_rar\trunk\tests\test.php:8
Stack trace:
#0 C:\php_rar\trunk\tests\test.php(8): RarArchive::open('does_not_exist....')
#1 {main}
thrown in C:\php_rar\trunk\tests\test.php on line 8