2016-07-11 9 views

答えて

6

あなたは異なる例外の種類をキャッチするために、複数のcatchのブロックを持つことができます。 以下を参照してください。

try { 
    /* code with exceptions */ 
} catch (MyFirstCustomException $e) { 
    // We know it is a MyFirstCustomException 
} catch (MySecondCustomException $e) { 
    // We know it is a MySecondCustomException 
} catch (Exception $e) { 
    // If it is neither of the above, we can catch all remaining exceptions. 
} 

あなたは例外がcatch文によってキャッチされると、以下のcatchの文のどれもが、彼らは例外と一致していても、トリガされないことを知っている必要があります。

get_classメソッドを使用して、例外を含むオブジェクトの完全なクラス名を取得することもできます。

12

get_classは動作するはずです:

try { 
    throw new InvalidArgumentException("Non Sequitur!", 1); 
} catch (Exception $e) { 
    echo get_class($e); 
} 
+0

まさに私が欲しかったもの、私はもう一度できるときアップアップします:) –

関連する問題