ceo@xxxxxxxxx wrote:
there is an art to using them, they compliment 'traditional' error
handling, and I agree they can hinder if used badly.
I don't think I've ever seen Exceptions used well...
Invariably, I end up having to write a wrapper function around every function implemented and catch all the Exceptions.
Otherwise, my code is littered with try/catch blocks for every little thing the other guy was too lazy to figure out how to handle gracefully.
ymmv
i use them often, basically if a boolean false won't do its a case of
throwing an exception.
let's say you have:
calls_fifty_methods($page_load_of_variables);
wrap that bit in a try catch and you get
try {
calls_fifty_methods($page_load_of_variables);
} catch ( DatabaseException $e) {
// handle that error
} catch ( FileNotFoundException $e) {
// handle
} catch ( VerySpecificException) {
// handle
} catch ( Exception $e ) {
// didn't expect this, notify devs, error log it and do X Y Z
}
try firing back error codes or something from 50 methods down and you
have a real can go wrong easily series of returning error codes and
processing the same anyways; or you could take the echo some html
approach from the function - which is wrong on so many levels or..
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php