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

Error::getPrevious - Returns previous Throwable | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

Error::getPrevious

(バージョン情報なし。おそらく SVN 版にしか存在しないでしょう)

Error::getPreviousReturns previous Throwable

説明

final public Throwable Error::getPrevious ( void )

Returns previous Throwable (the third parameter of Error::__construct()).

パラメータ

この関数にはパラメータはありません。

返り値

Returns the previous Throwable if available or NULL otherwise.

例1 Error::getPrevious() example

Looping over, and printing out, error trace.

<?php
class MyCustomError extends Error {}

function 
doStuff() {
    try {
        throw new 
InvalidArgumentError("You are doing it wrong!"112);
    } catch(
Error $e) {
        throw new 
MyCustomError("Something happened"911$e);
    }
}


try {
    
doStuff();
} catch(
Error $e) {
    do {
        
printf("%s:%d %s (%d) [%s]\n"$e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode(), get_class($e));
    } while(
$e $e->getPrevious());
}
?>

上の例の出力は、 たとえば以下のようになります。

/home/bjori/ex.php:8 Something happened (911) [MyCustomError]
/home/bjori/ex.php:6 You are doing it wrong! (112) [InvalidArgumentError]

参考


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

フォーラムで「Error::getPrevious - Returns previous Throwable」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | Error::getPrevious - Returns previous Throwable」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: