Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 4:55 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Article
 Article subject: Define your own exception class
PostPosted: Mon Oct 27, 2008 11:52 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

Code:

<?php
   
class InvalidEmailException extends Exception {
   
      function
__construct($message, $email) {
         
$this->message = $message;
         
$this->notifyAdmin($email);
      }

      
private function notifyAdmin($email) {
         
mail("admin@yourdomain.com","INVALID EMAIL",$email,"From:web@example.com");
      }

   }

   class
subscribe {
      function
validateEmail($email) {
         
try {
            if (
$email == "") {
               
throw new Exception("You must enter an e-mail address!");
            } else {
               list(
$user,$domain) = explode("@", $email);
                  if (!
checkdnsrr($domain, "MX")) {
                     
throw new InvalidEmailException("Invalid e-mail address!", $email);
                  } else {
                     return
1;
                  }
            }
         }
catch (Exception $e) {
            echo
$e->getMessage();
         }
catch (InvalidEmailException $e) {
            echo
$e->getMessage();
         }
      }

      function
subscribeUser() {
         echo
$this->email." added to the database!";
      }

   }

   
$_POST['email'] = "someuser@example.com";

   if (isset(
$_POST['email'])) {
      
$subscribe = new subscribe();
      if(
$subscribe->validateEmail($_POST['email']))
         
$subscribe->subscribeUser($_POST['email']);
   }

?>

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Issues with class, need help
 C C++ program help using class
 Exception handling
 Not to find nativeEncoder class jar
 Exception errror at LocalDevice device = LocalDevice.getLoc
 PHP class example
 concrete class
 Having a hard time with this class need help deseperately.
 Exception is not clear
 Ladies & Gents Watches for 150-450 AED ,High Class.

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google Adsense [Bot] and 1 guest



Jump to:  
Previous Article | Next Article 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team