Code has been added to clipboard!

Using PHP Try Catch

Example
<?php
  class customException extends Exception {
    public function error_message() {
      //error message
      $error_msg = $this->getMessage().' is no valid E-Mail address.';
      return $error_msg;
    }
  }

  $email = "[email protected]";

  try {
    try {
      //checking for "example" in mail address
      if(strpos($email, "example") !== FALSE) {
        //throwing an exception if email is not valid
        throw new Exception($email);
      }
    } catch(Exception $e) {
      //re-throwing exception
      throw new customException($email);
    }
  } catch (customException $e) {
    //display custom message
    echo $e->error_message();
  }
?>