ホームページ  >  記事  >  バックエンド開発  >  phpの事前定義された例外

phpの事前定義された例外

伊谢尔伦
伊谢尔伦オリジナル
2016-11-22 11:07:11991ブラウズ

1.Exception

(PHP 5 >= 5.1.0)

はじめに

Exception はすべての例外の基本クラスです。

Method

Exception::__construct — 例外コンストラクター

Exception::getMessage — 例外メッセージの内容を取得する

Exception::getPrevious — 例外チェーン内の前の例外を返す

Exception::getCode — 例外コードを取得する

Exception::getFile — 例外が発生したプログラム ファイルの名前を取得します

Exception::getLine — 例外が発生したファイル内のコードの行番号を取得します

Exception::getTrace — 例外追跡情報を取得します

Exception::getTraceAsString — 文字列型の例外追跡情報を取得します

Exception::__toString — 例外オブジェクトを文字列に変換します

Exception::__clone — 例外の複製

2.ErrorException

(PHP 5 >= 5.1. 0)

はじめに

エラー例外。

例 #1 set_error_handler() 関数を使用してエラー情報を ErrorException にホストします

<?php
    function exception_error_handler($errno, $errstr, $errfile, $errline ) {
        throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
    }
    set_error_handler("exception_error_handler");
    /* Trigger exception */
    strpos();
?>

上記のルーチンの出力は次のようになります。 :getSeverity — 例外の重大度を取得します

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。