Lesson content
Read, practise, then check your understanding
Error and Exception implement Throwable. Catch specific failures where recovery, translation, or contextual reporting is possible; preserve the original throwable.
Practical example
<?php
try { $config = loadConfig($path); }
catch (JsonException $error) { throw new RuntimeException('Configuration is invalid', 0, $error); }
finally { /* unconditional cleanup */ }
Production should log rather than display internal errors. A top-level handler can format uncaught failures, while transaction and resource code still needs local cleanup. Avoid empty catches, sensitive log data, and converting every warning without policy.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.