Can anybody tell me how are exceptions handled in PHP? I have this code
try{
$this->b->methodthatraisesexception();
}
catch(Exception $ex){
echo "Hi Hi hi, you tried to deleted a non existing file";
}
When i try to run this code instead of seeing the echo message, i see some kind of weird PHP error occured message. Btw, the above method is contained in A‘s class which handles exceptions. It is calling to b‘s method which generates error but doesn’t have try catch. I see the below given error. Instead of my own echo statement. Please let me know if anything is unclear.
EDIT
A PHP Error was encountered
Severity: Warning
Message: unlink(C:/Program Files/wamp/www/\College\uploads\4c4b29de80e39.jpg) [function.unlink]: No such file or directory
Filename: models/settings.php
Line Number: 31
Thanks in advance 🙂
unlink() doesn’t throw exceptions.
http://php.net/manual/en/function.unlink.php
As far as throwing exceptions, you just throw ’em. You don’t declare that the class throws them.
https://www.php.net/manual/en/language.exceptions.php
Update:
Basically, do this where unlink() is called: