Hai mai provato il try-catch? Ti passo un link:

http://uk2.php.net/exceptions