RarException::setUsingExceptions

(PECL rar >= 2.0.0)

RarException::setUsingExceptionsActivar y desactivar el manejador de errores con excepciones

Descripción

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

Si y sólo si el argumento es TRUE, entonces, en lugar de emitir advertencias y devolver un valor especial indicando error cuando la biblioteca UnRAR encuentre un error, una excepción de tipo RarException será lanzada.

Las excepciones también será lanzado para los siguientes errores, que se producen fuera de la biblioteca (su código de error será -1):

Parámetros

using_exceptions

Debe ser TRUE para activar lanzamiento de excepciones, FALSE para descativarlo (el valor por defecto).

Ejemplos

Ejemplo #1 Ejemplo de 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); //not reached
?>

El resultado del ejemplo sería algo similar a:

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

Ver también