Try and catch in Error Handling in PHP.

In this tutorial, we are showing error handling because it can be used in multiple programs for checking error messages. There are multiple scripts those use multiple exceptions to check into multiple conditions. we can also use multiple conditions like: - if, if else blocks into units, switch case, nested conditions with exception. every exception may have different exception using class module and returns different error statements and messages:
We can easily understand with the help of Example: - 
getLine().' in '.$this->getFile()
    .': '.$this->getMessage().' This is not a valid EMail ID';
    return $errorMsg;
  }
}

     $emailid = "ashok@estuffcage...com";

  try {
       //check if
      if(filter_var($emailid, FILTER_VALIDATE_EMAIL) === FALSE) {
      //throw an exception if your given email is not valid
     throw new mynewException($emailid);
   }
       //check for "example" in mail address
      if(strpos($emailid, "example") !== FALSE) {
      throw new myException("$emailid is an example e-mail");
  }
}

   catch (mynewException $s) {
        echo $s->errorMessage();
     }

   catch(myException $s) {
          echo $s->getMessage();
    }
 ?> 

You Might Also Read : -

0 comments :

Post a Comment

 
# Top