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