Page 352 - CITS - CSA - TP (Volume 1) - Hindi
P. 352
कंप्यूटर सॉफ्टवेयर एप्लीकेशन- CITS
II क म ए े शन ास का उपयोग करना (Using a custom exception class)
1 टे एिडटर ओपन करे
2 िन िल खत कोड िलख
<html >
<head>
<title> custom exception </title>
</head>
<body>
<?php
// Define a custom exception class
class CustomException extends Exception
{
public function errorMessage()
{
// Custom error message
$errorMsg = ‘Error on line ‘ . $this->getLine() . ‘ in ‘
. $this->getFile() . ‘<br/> <b> . $this->getMessage() .
‘</b> ;
return $errorMsg;
}
}
// Function to validate an email address
function validateEmail($email)
{
// Check if the email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
// Throw a custom exception if the email is not valid
throw new CustomException($email);
}
// Return true if the email is valid
return true;
}
336
CITS : IT & ITES - कं ूटर सॉ वेयर ए ीके शन - अ ास 60

