Exception Handling — PHP Technical Interview Questions & Answers
Exception Handling
Exception Handling
- Exception Handling is a PHP topic. In plain words you use it for divide total / count in a report script. Don’t start with a slogan — start with that picture.
- Smallest example: try/catch + log. Type it, run it, and say what you see. If you can do that from memory, you know Exception Handling.
- From the example next to this theory: Exception Handling: scores array, print avg, then high marks.
- Trap: empty catch. Fix that before you talk about advanced PHP.
- Viva: what is Exception Handling? Then show try/catch + log. Then name the trap.
Technical Interview Tip: What is Exception Handling? Show this: try/catch + log. Trap: empty catch.
Code Examples for Exception Handling
Exception Handling — working example
<?php
// Exception Handling
$scores = [80, 90, 70];
$avg = array_sum($scores) / count($scores);
echo "avg=" . number_format($avg, 1) . "\n";
foreach ($scores as $s) {
if ($s >= 80) echo "high: $s\n";
}Exception Handling: scores array, print avg, then high marks. Say the output.
How to Explain Exception Handling to an Interviewer
What is Exception Handling?
Used for divide total / count a report script Not just the heading
Give one small example of Exception Handling.
try/catch + log Exception Handling: scores array, print avg, then high marks
What mistake do beginners make with Exception Handling?
empty catch Show the fix
Where do you use Exception Handling?
a report script divide total / count