How can the requested URL be passed and processed in PHP error handling?

When handling errors in PHP, it is important to capture the requested URL that triggered the error for debugging or logging purposes. This can be achieved by accessing the $_SERVER['REQUEST_URI'] variable, which contains the requested URL. By including this variable in your error handling logic, you can easily track which URL caused the error.

// Get the requested URL
$request_url = $_SERVER['REQUEST_URI'];

// Handle the error and include the requested URL
try {
    // Code that may cause an error
} catch (Exception $e) {
    // Log the error along with the requested URL
    error_log("Error occurred at $request_url: " . $e->getMessage());
}