PHP5 exception handling mechanism [13] - more information related to exception

xiaoxiao2021-03-06  68

Get an abnormally related information

The following is the code used to format the output exception information:

INDEX_PHP5_6.PHP

'realcommand ")); $ helper-> runcemmand ();} catch (Exception $ E) {Print "

". GET_CLASS ($ E). " / n"; print "

{$ E-> getMessage ()} ({$ E-> getcode ()} / n / n "; print" file: {$ E-> getFile ()}
getLine ()}
GetTraceAsstring (); Die;}}} front :: main ();?>>

If your Realcommand class cannot be instantiated (for example, you declare its constructor as private) and run the above code, you can get this output:

REFLECTIONEXCEPTION

Access to non-public constructor of class realcommand (0)

File: c: /myweb/apache/htdocs/php5exception/index_php5_4.phpline: 31 # 0 c: /myweb/apache/htdocs/php5Exception/index_php5_5.php (25): commandManager-> getcommandObject ()

# 1 c: /myweb/apache/htdocs/php5exception/index_php5_6.php (10): Requesthelper-> Runcommand ('Realcommand')

# 2 c: /myweb/apache/htdocs/php5exception/index_php5_6.php (23): Front :: main ()

# 3 {main}

You can see getFile () and getLine () return to an exception file and the number of files. The getStackasstring () method returns the details of each layer that causes an exceptional method. From # 0 until # 4, we can clearly see the path of the abnormality.

You can also use the GetTrace () method to get this information, getTrace () returns a multi-dimensional array. The first element contains an abnormal position, and the second element contains the details of the external method call until the highest layer call. Each element of this array itself is also an array that contains the following key names:

KEY Meaning File Generates Experient File Line Generates Exception Class Method The number of lines of the line FUNCTION generates an abnormal function / method Class Call Class The class Type call type: '::' Indication Call Static class '->' represents instantiated call (First instantiate the generated object recall) the parameters accepted by the ARGS class method

转载请注明原文地址:https://www.9cbs.com/read-121816.html

New Post(0)