07-20-2023, 03:31 PM
Everyone talks about how important exception handling is. I have never had the need to handle them until recently:
try {
$pdo = new PDO($dns);
} catch (Exception $e) {
throw new Exception($e);
}
Another more general example would be:
if ($something) {
throw new Exception('Ouch! I can't do that!');
}
After a little online research, I found that many examples/solutions online simply echo them. (
**Question #1:** Where should I catch exceptions; in the Model or Controller of a **MVC**ish framework?
**Question #2:** What should catching it do? Log it, email it, display 503?
try {
$pdo = new PDO($dns);
} catch (Exception $e) {
throw new Exception($e);
}
Another more general example would be:
if ($something) {
throw new Exception('Ouch! I can't do that!');
}
After a little online research, I found that many examples/solutions online simply echo them. (
[To see links please register here]
) Some don't have solutions. ([To see links please register here]
) & ([To see links please register here]
) And others, I just dont understand. ([To see links please register here]
)**Question #1:** Where should I catch exceptions; in the Model or Controller of a **MVC**ish framework?
**Question #2:** What should catching it do? Log it, email it, display 503?