Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class EmptyName extends Exception
- {
- private $_nameError;
- public function __construct( $message )
- {
- $this->_nameError = $message;
- }
- public function getNameError()
- {
- return $this->_nameError;
- }
- }
- class EmptyEmail extends Exception
- {
- private $_emailError;
- public function __construct( $message )
- {
- $this->_emailError = $message ;
- }
- public function getEmailError()
- {
- return $this->_emailError;
- }
- }
- $name = "someone";
- $email = "";
- try
- {
- if( empty( $name ) )
- {
- throw new EmptyName( "Error name must not be empty" );
- }
- if( empty( $email ) )
- {
- throw new EmptyEmail( "Error email must not be empty" );
- }
- else
- {
- echo "Name : $name" . "<br>" ."Email : $email";
- }
- }
- catch( EmptyName $e )
- {
- echo $e->getNameError();
- }
- catch ( EmptyEmail $e )
- {
- echo $e->getEmailError();
- }
- catch ( Exception $e )
- {
- echo $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement