What are the potential pitfalls of using file_get_contents to retrieve JSON data in PHP?

When using file_get_contents to retrieve JSON data in PHP, potential pitfalls include not handling errors properly, such as when the file is not found or the request times out. To solve this issue, it is recommended to use the file_get_contents function in combination with error handling techniques such as try-catch blocks to handle exceptions.

$url = 'https://example.com/data.json';

try {
    $json = file_get_contents($url);
    if ($json === false) {
        throw new Exception('Error retrieving JSON data');
    }

    // Process JSON data here

} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}