file error handling
Permalink Browser Info Environment
HI ...
using this addon (... and I LOVE it) i have trouble if I have some external file opening issues.
Let me explain:
I want to open a .csv file and display data... it's a simple routine in PHP (see below) and works great BUT ONLY if csv file exists
If the csv file does not exists i get a c5 error (see attached) and then I have to go back on page to delete the version because there is no way to even see any more the block in that page
Would it be possible to handle the error in some way (maybe with a meaningful message or just an error warning) but leaving the block accessible for maintenance ?
Thank you so much in advance
Michele
using this addon (... and I LOVE it) i have trouble if I have some external file opening issues.
Let me explain:
I want to open a .csv file and display data... it's a simple routine in PHP (see below) and works great BUT ONLY if csv file exists
If the csv file does not exists i get a c5 error (see attached) and then I have to go back on page to delete the version because there is no way to even see any more the block in that page
Would it be possible to handle the error in some way (maybe with a meaningful message or just an error warning) but leaving the block accessible for maintenance ?
Thank you so much in advance
Michele
<?php // Create a table from a csv file if (($handle = fopen("test.csv", "r")) !== false) { echo "<html><body><table>\n\n"; $f = fopen("test.csv", "r"); while (($line = fgetcsv($f)) !== false) { $row = $line[0]; $cells = explode(";",$row); echo "<tr>"; foreach ($cells as $cell) { echo "<td>" . htmlspecialchars($cell) . "</td>"; } echo "</tr>\n"; } fclose($f);
Viewing 15 lines of 21 lines. View entire code block.
Type: | Discussion |
---|---|
Status: | In Progress |
I see the issue here, and this could be generalized to any exception raised during the execution of the code.
There are two possibilities:
1. I could update the plugin so that when an exception occurs, I print an explicit error message in place of the content. If I find the time, I may release an update.
2. The code should be protected against potential errors during the execution. For instance, in your case, you should add a try-catch statement like: