Common PHP function block_exception and timestamp-php (33), php timestamp Conversion

Source: Internet
Author: User

Common PHP function block_exception and timestamp-php (33), php timestamp Conversion

Exception (next)

A simple Exception Handling instance

<? Phptry {$ error = 'always throw this error'; throw new Exception ($ error); // create an Exception object and throw echo 'neverexecuted' through the throw statement '; // from here on, the code in the try code block will not be executed again} catch (Exception $ e) {echo 'caught exception: ', $ e-> getMessage (), "\ n"; // output the captured exception message} echo 'Hello world'; // the program does not crash and continues to run down?>

Built-in Exception Handling

 

<? PhpclassException {protected $ message = 'unknownexception '; // exception information protected $ code = 0; // User-Defined Exception code protected $ file; // The file name protected $ line that has encountered an exception; // The code line number that has encountered an exception function _ construct ($ message = null, $ code = 0); finalfunctiongetMessage (); // return the exception message finalfunctiongetCode (); // return the Exception Code finalfunctiongetFile (); // return the file name finalfunctiongetLine () with an exception (); // return the code line number finalfunctiongetTrace (); // The backtrace () array finalfunctiongetTraceAsString (); // formatted as a string GetTrace () Information/* method that can be reloaded */function _ toString (); // output string}?>

 

 

<? Php/* a custom exception handling class, but it must be a subclass of the extended Exception handling class */class MyExceptionextends Exception {// redefine the constructor so that the first parameter message is changed to the public function _ construct ($ message, $ code = 0) {// you can define your own code here. // we recommend that you call parent: construct () to check whether all variables have been assigned parent :: __construct ($ message, $ code);} public function _ toString () {// rewrite the parent CLASS method and customize the Style return _ CLASS _ output of the string __. ":[". $ this-> code. "]:". $ this-> message. "<br>";} public function customFunction () {// custom one for this exception Processing Methods echo "handle exceptions of this type by custom method <br>" ;}}?>

Custom exception

 

<? Phptry {// capture an exception using a custom exception class and handle the exception $ error = 'Allow throwing this error'; throw new MyException ($ error ); // create a custom exception class object and throw echo 'never executed' through the throw statement; // from here, the code in the try code block will not be executed again} catch (MyException $ e) {// capture the custom exception object echo 'catch exception :'. $ e; // output the captured exception message $ e-> customFunction (); // process the exception through the methods in the custom exception object} echo 'Hi '; // The program does not crash and continues to run down?>


Capture multiple exceptions

 

After try code, you must provide at least one catch code block. You can also associate multiple catch code blocks with one try code block. You can use multiple catch methods to catch exceptions generated by different classes. Pay attention to the sequence.

2 Timestamp

2.1 UNIX Timestamp

 

Unix timestamp:

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.