PHP Exception Handling

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.