I'm new to using objects / classes in PHP, and I'm curious about EXCEPTIONS , TRY and CATCH
In the example below, I have all 3 shown in use. Obviously, an exception is a kind of way to throw an error, but I don't understand why? In the code below, could I easily show some kind of error or something without exception there?
The following is an example of using try and catch. It seems to me that I am using if / else. Perhaps I am mistaken, this is the way I see them without knowing anything, I understand that you can encode anything in PHP without using them, which is the reason there is an advantage in using this material compared to traditional methods ?
<?PHP
if($something === $something_else){
}else if($something === $something_else_again){
}else{
throw new Exception('Something went wrong!');
}
try{
$thumb = PhpThumbFactory::create('/path/to/image.jpg');
}
catch (Exception $e){
}
?>