PHP Common function Block _ exception and timestamp-php (), php timestamp conversion _php Tutorial

Source: Internet
Author: User

PHP Common function Block _ exception and timestamp-php (), PHP timestamp conversion


Exception (Next)

A simple exception handling instance

 
  PHPtry  {$error'alwaysthrow this error'; Throw New Exception ($error); // creates an exception object, thrown by a throw statement ' neverexecuted ' ; // from here, the code inside the try code block will no longer be executed Catch  'caught exception:'\ n'; // output-caught exception message  'HelloWorld'// program does not crash continue down execution ?>

System comes with exception handling

 phpclassexception{protected$message ='unknownexception';//Exception Informationprotected$code =0;//user-defined exception codesprotected$file;//the file name of the exception that occurredprotected$line;//the line number of the code where the exception occurredFunction__construct ($message =NULL, $code =0); Finalfunctiongetmessage ();//Return exception InformationFinalfunctiongetcode ();//return Exception CodeFinalfunctiongetfile ();//returns the file name of the exception that occurredFinalfunctiongetline ();//returns the line number of the code where the exception occurredFinalfunctiongettrace ();//backtrace () arrayFinalfunctiongettraceasstring ();//has been rasterized into a stringthe Gettrace () information/*methods that can be overloaded*/function__tostring ();//A string that can be output}?>

 Php/*a custom exception-handling class, but must be a subclass of the exception-handling class within the extension*/classmyexceptionextends exception{//Redefine the constructor so that the first parameter message becomes a property that must be specified Publicfunction __construct ($message, $code =0){//You can define some of your own code here//It is recommended to call Parent::construct () at the same time to check that all variables have been assigned valuesparent::__construct ($message, $code);} Publicfunction __tostring () {//overriding the parent class method, customizing the style of the string outputreturn__class__.":[".$ This->code."]:".$ This->message."
";} Publicfunction Customfunction () {//customize a processing method for this exceptionEcho"handle this type of exception as a custom method
";}}?>

Custom exceptions

 
  PHPtry// Use a custom exception class to catch an exception and handle the exception ' allow this error to be thrown '; Throw New myexception ($error); // creates a custom exception class object that is thrown by the throw statement ' never executed ' // from here, the code inside the try code block will no longer be executed Catch // capturing a custom exception object '  '// output caught exception message //  exception handled by a method in the custom exception object ' How are you? ' // program does not crash continue down execution ?>


Capturing multiple exceptions

After the try code, you must give at least one catch code block, or you can associate multiple catch blocks with a try block of code. You can use multiple catches to catch exceptions from different classes. Note the order.

2 time stamp

2.1 Unix Timestamp

Unix Timestamp:

http://www.bkjia.com/PHPjc/1006442.html www.bkjia.com true http://www.bkjia.com/PHPjc/1006442.html techarticle PHP Common Function Block _ exception and timestamp-php (), PHP timestamp conversion exception (next) A simple exception handling instance? php try {$error = ' always throw this error '; th ...

  • 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.