略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: RarException::setUsingExceptions

2024-12-22

RarException::setUsingExceptions

(PECL rar >= 2.0.0)

RarException::setUsingExceptionsActivate and deactivate error handling with exceptions

说明

public static RarException::setUsingExceptions(bool $using_exceptions): void

If and only if the argument is true, then, instead of emitting warnings and returning a special value indicating error when the UnRAR library encounters an error, an exception of type RarException will be thrown.

Exceptions will also be thrown for the following errors, which occur outside the library (their error code will be -1):

参数

using_exceptions

Should be true to activate exception throwing, false to deactivate (the default).

返回值

没有返回值。

范例

示例 #1 RarException::setUsingExceptions() example

<?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); //not reached
?>

以上例程的输出类似于:

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

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/rarexception.setusingexceptions.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3