xploita Posted April 8, 2007 Share Posted April 8, 2007 when coding.say that i call function UpdateLog() which must open a file,append to it then close it. alot of errors could rise(file is not there,unable to write..etc). which is better,to return a false value and handle the error outside the function UpdateLog(),or to end it right there inside the UpdateLog() function if it couldn't find/update the file? regards Quote Link to comment https://forums.phpfreaks.com/topic/46191-handling-errors/ Share on other sites More sharing options...
wildteen88 Posted April 9, 2007 Share Posted April 9, 2007 I'd would handle all error aspects which the file you are writing to having write permission, file not found etc in side the function itself. Quote Link to comment https://forums.phpfreaks.com/topic/46191-handling-errors/#findComment-224916 Share on other sites More sharing options...
xploita Posted April 9, 2007 Author Share Posted April 9, 2007 inside which funciton ? the calling function or the one that actually writes to the file? Quote Link to comment https://forums.phpfreaks.com/topic/46191-handling-errors/#findComment-224934 Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 a wild guess... inside the function that writes to the file... Quote Link to comment https://forums.phpfreaks.com/topic/46191-handling-errors/#findComment-224937 Share on other sites More sharing options...
trq Posted April 9, 2007 Share Posted April 9, 2007 IMO its best to have the calling code decide wether or not to kill the application based on wether or not your function call failed or succeeded. If your using PHP5, use exceptions, this makes this sort of descision making alot simpler. Quote Link to comment https://forums.phpfreaks.com/topic/46191-handling-errors/#findComment-224967 Share on other sites More sharing options...
Koobi Posted April 9, 2007 Share Posted April 9, 2007 i agree with thorpe. if you're writing a class or a function, you probably use it more than once and for different apllications of that function, you might have to react differently based on the error. thorpe mentioned exceptions in PHP 5 (i'm only just learning that :/), but if you're on PHP 4, try set_error_handler() and trigger_error() Quote Link to comment https://forums.phpfreaks.com/topic/46191-handling-errors/#findComment-224986 Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 ok thanks for correcting me.. as i said.. wild guess...hehe... damn i really feel like a noob!! dont like it *gone reading more about php* Quote Link to comment https://forums.phpfreaks.com/topic/46191-handling-errors/#findComment-224989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.