Error Handling — PHP Technical Interview Questions & Answers
Error Handling
Error Handling
- Error 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 Error Handling.
- From the example next to this theory: Error Handling: scores array, print avg, then high marks.
- Trap: empty catch. Fix that before you talk about advanced PHP.
- Viva: what is Error Handling? Then show try/catch + log. Then name the trap.
Technical Interview Tip: What is Error Handling? Show this: try/catch + log. Trap: empty catch.
Code Examples for Error Handling
Error Handling — working example
<?php
// Error 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";
}Error Handling: scores array, print avg, then high marks. Say the output.
How to Explain Error Handling to an Interviewer
What is Error Handling?
Used for divide total / count a report script Not just the heading
Give one small example of Error Handling.
try/catch + log Error Handling: scores array, print avg, then high marks
What mistake do beginners make with Error Handling?
empty catch Show the fix
Where do you use Error Handling?
a report script divide total / count