Answer the question
In order to leave comments, you need to log in
PHP/Yii2 how to properly handle exceptions?
I admit, I'm a noob when it comes to working with exceptions. Previously, for the most part, I did without them, but now I want to figure it out.
Why PHP has two base classes \Exception and \ErrorException?
Why does Exception catch Unknown Property Exception but not, say, division by 0?? And in ErrorException exactly the opposite?
try {
$myClass->myUnknowProperty;
//10/0; //error!!!1
// throw new \ErrorException ("tralala"); // error!!!
} catch (\Exception $e) {
log("warning UnknowProperty");
}
try {
//$myClass->myUnknowProperty; //error!!
10/0;
//throw new \Exception("tralala"); // error!!
} catch (\ErrorException $e) {
log("warning division by zero");
}
Answer the question
In order to leave comments, you need to log in
Why does Exception catch Unknown Property Exception but not, say, division by 0?? And in ErrorException exactly the opposite?
Recently, a good article on this topic was published on Habré, with examples for Yii:
Proper use of Exceptions in PHP .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question