0% found this document useful (0 votes)
49 views2 pages

Program For User Defined Exception / Exp - HTML

This document contains code for a PHP program that defines and handles user-defined exceptions. It includes an HTML form to collect a name and age from the user. The PHP code uses regular expressions to validate the input and throws custom exception objects if validation fails. If no exceptions are thrown, the valid name and age are output.

Uploaded by

Selva Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

Program For User Defined Exception / Exp - HTML

This document contains code for a PHP program that defines and handles user-defined exceptions. It includes an HTML form to collect a name and age from the user. The PHP code uses regular expressions to validate the input and throws custom exception objects if validation fails. If no exceptions are thrown, the valid name and age are output.

Uploaded by

Selva Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*PROGRAM FOR USER DEFINED EXCEPTION*/

Exp.html
<html>

<head>

<title>User defined Exception</title>

</head>

<body>

<font size="3">USER DEFINED EXCEPTION</font><br><br>

<form action="Exception.php" method="post">

Enter the Name:<input type="text" name="strg"><br>

Enter the Age:<input type="text" name="num"><br>

<input type="submit" value="submit"></form>

</body>

</html>

Exception.php
?php

$name=$_POST['strg'];

$age=$_POST['num'];

classNameException extends Exception{}

classAgeException extends Exception{}

try

if(preg_match('/[^a-z]/i',$name))

{
throw new NameException();

elseif(preg_match('/[^0-9]/i',$age))

throw new AgeException();

else

echo"The given name is ".$name.'<br>';

echo"The given age is ".$age.'<br>';

echo"It is valid<br>";

catch(NameException $e)

echo"The given name is invalid "."<br>";

echo"$name contains numeric other than a-z A-Z";

catch(AgeException $e)

echo"The given age is invalid "."<br>";

echo"$age contains string other than 0-9";

?>

You might also like