Page 1 of 1

Get error information

Posted: Mon May 01, 2006 11:30 pm
by alex.barylski
Ok Feyd, trick question...

I need to detect when a include_* has been called and failed because file didn't exist...but instead of choking the script...I need to be able to get the name of the path of the file requested programatically, without parsing output errors...

As that obviously would be a bad way of getting the path requested...cuz i'm sure that changes frequently, language, etc...

Possible?

p.s-This is not a situation where I can use file_exists() I need the script to execute, fail throwing a warning and then be able to get the path from that warning of the requested file...

I've considered using the buffer functions and extracting the suggested path, but that doesn't seem fitting as the message could likely change drastically from one machine to another...???

I've looked for a get last error type funciton and couldn't find anything??? :(

Posted: Mon May 01, 2006 11:32 pm
by alex.barylski
I though this maybe possible with try/catch but I can't seem to find anything on it???

Doesn't PHP5 support try/catch? :?

Posted: Mon May 01, 2006 11:48 pm
by John Cartwright
I think what your after is exception handling.

Code: Select all

try {
   $includePath = 'path/to/file.txt';
   
   if (!@include($includePath)) {
      throw new Exception('Cannot find file '. $includePath);
   }

   echo 'File included fine!';

} catch (Exception $e) {
   echo 'Caught exception: ',  $e->getMessage(), "\n";
}
Untested.

Posted: Mon May 01, 2006 11:56 pm
by alex.barylski
That is the try/catch blocks I was looking for...

But it didn't even occur to me that they wouldn't solve my problem...as my problem is a parse/compile time error, not runtime...so exceptions won't work :(

If there was a way to check a stack of errors/warnings the parser threw...I could maybe work with that :)

Posted: Tue May 02, 2006 12:02 am
by feyd
set_error_handler() is your friend.