PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

RarException::setUsingExceptions - 例外によるエラー処理の有効化および無効化を行う | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

RarException::setUsingExceptions

(PECL rar >= 2.0.0)

RarException::setUsingExceptions例外によるエラー処理の有効化および無効化を行う

説明

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

引数に TRUE を指定すると、UnRAR ライブラリがエラーに遭遇したときの挙動を変更し、 警告を発してエラーを示す値を返すのではなく RarException 型の例外をスローするようにします。

例外は次のエラーのときにもスローされます。これらはライブラリの外部で発生します (エラーコードは -1 です)。

  • 既に閉じた RarArchive オブジェクトやそれに関する RarEntry オブジェクトへのアクセスを試みたとき。
  • 存在しないエントリを RarArchive::getEntry() で取得しようと試みたとき。

パラメータ

using_exceptions

例外をスローさせるときは TRUE、例外をスローさせないときは FALSE (デフォルト)。

例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); //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

参考


忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「RarException::setUsingExceptions - 例外によるエラー処理の有効化および無効化を行う」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | RarException::setUsingExceptions - 例外によるエラー処理の有効化および無効化を行う」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: