+ 3
Php exception handling
So i was trying to advance my knowledge on php and i came across the php exception handling tutorial on w3schools but am not convinced on why php needs it when u can just use if else statement to check for errors and handle it, would like anyone that actually uses php exception handling in real life code implementation to help me understand the need for it, Thanks.
2 Answers
+ 1
exception handling saves you from unforseen bugs. usually, if-else caters for what the programmer expects might occur.
0
Throw and catch blocks in php are better for handling errors specifically. That's what they're for. Using if else statements in some situations can be clumsy and bulky for your code.