PHP Exception Handling Classes

Source: Internet
Author: User
Tags getmessage php exception handling

<?PHPHeader(' Content-type:text/html;charset=utf-8 ');//Create an email exception handling classclassEmailexceptionextends Exception{}//creating the PWD exception handling classclassPwdexceptionextends Exception{     Public function__tostring () {return $this->getmessage (). ' In file: '.$this->getfile (). ' On line: '.$this-GetLine (); }}functionReg$reginfo=NULL){    //throw different exceptions based on different errors    if(Empty($reginfo) || !isset($reginfo)) {        Throw New Exception(' argument is illegal '); }    if(Empty($reginfo[' Email '])) {        Throw NewEmailexception (' message is empty '); }    if($reginfo[' pwd ']! =$reginfo[' Repwd ']) {        Throw NewPwdexception (' two times password inconsistent! ‘); }}//receive different exceptions and deal with them in a targeted direction! Try{reg (Array(' Email ' = ' [email protected] ', ' pwd ' = ' 123 ', ' repwd ' and ' 1231 ' ));} Catch(Exception $e) {    Echo $e-getMessage ();} Catch(emailexception$ee) {    Echo $ee-getMessage ();} Catch(pwdexception$ep) {    Echo $ep;}

PHP Exception Handling Classes

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.