Mega Code Archive

 
Categories / Php / File Directory
 

File open with exception checking

<?php try {     $fh = fopen("data.txt", "r");     if (! $fh) {         throw new Exception("Could not open the file!");     } } catch (Exception $e) {     echo "Error (File: ".$e->getFile().", line ".           $e->getLine()."): ".$e->getMessage(); } ?>