EXCEPTION
EXCEPTION
<?php
class Aime extends Exception {
public function __construct($message) {
parent::__construct($message);
}
}
<?php: This indicates the beginning of a PHP script.
class Aime extends Exception {}: This defines a custom exception class named Aime
that extends the built-in Exception class.
public function __construct($message) {}: This is the constructor method for the
Aime class, which takes a $message parameter.
try {
try {
$numerator = 10;
$denominator = 0;
if ($denominator == 0) {
throw new DivisionByZeroError();
}
$numerator = 10; $denominator = 0;: These lines define and initialize the variables
numerator and denominator.
catch (Aime $e) { echo "Caught an exception: " . $e->getMessage(); }: This catches
the Aime exception and prints the custom error message.
In essence, this script attempts a division by zero, catches the standard error for
this, converts it to a custom error message, and then catches and displays that
custom error message.