What is the significance of the NotFoundException class extending the Exception class in PHP?

Extending the Exception class in PHP allows the NotFoundException class to inherit all the properties and methods of the Exception class. This means that the NotFoundException class can utilize the built-in functionality of the Exception class, such as being able to set a custom error message and code. By extending the Exception class, the NotFoundException class can be used to specifically handle situations where a certain resource or object is not found, providing more specific and informative error handling in PHP.

class NotFoundException extends Exception {
    public function __construct($message = "", $code = 0, Throwable $previous = null) {
        parent::__construct($message, $code, $previous);
    }
}

// Example usage
try {
    // Code that may throw a NotFoundException
    throw new NotFoundException("Resource not found", 404);
} catch (NotFoundException $e) {
    echo "Error: " . $e->getMessage();
}