Process of exception handling:
Error, then throw new Exception (' Self fill out the output message ', error number code) →
Pass
1 Try{2 //the code that will be tested3}Catch(Exception $e){//$e is the object to throw over $error4 $e->getmessage ();//the message of the new exception object5 $e->getcode ();//the code of the new Exception object6 7}
Exception is the exception handling class for the system
Exception {/* Properties */protected string $message ; protected int $code ; protected string $file ; protected int $line ; /* Method */public __construct ([ string
$message
= "" [, int
$code
= 0 [, Exception
$previous
=
]]] )final public string getMessage ( void) final public Exception getprevious ( void) final public int getcode ( void) final public string getFile ( void) final public int getLine ( void) final public array gettrace ( void) final public string gettraceasstring ( void) public string __tostring ( void) final private void __clone ( void)
}
The usual methods are--getmessage (), GetLine (), GetCode (), GetFile ().
The exception is usually recorded with a log class ErrLog.
1 classerrlog{2 Public Static functionLogs$err){3 $fp=fopen(' File path ', ' open mode ');//Open the file, prepare to load.4 $err=Date(' y-m-d h-i=s '). " \ r \ n ".$err;//record the time, TXT file line-up with \ r \ n5 fwrite(' Write-in Path FP ', ' $err ')6 } 7 8}
Under Catch Errlog::logs ($err), call the class, write the contents in
PHP Exception Handling