📝 PHP Error Handling – MCQ Test
📚 Section A: Basic (1 Mark Each)
1. Which function is used to report errors in PHP?
A) display_error()
B) error_reporting()
C) show_error()
D) report_error()
✅ Answer: B
2. Which error type stops script execution?
A) Notice
B) Warning
C) Fatal Error
D) Deprecated
✅ Answer: C
3. What does E_NOTICE indicate?
A) Critical error
B) Minor issue
C) Syntax error
D) Database error
✅ Answer: B
4. Which function is used to display errors?
A) ini_set()
B) show_error()
C) print_error()
D) log_error()
✅ Answer: A
5. What is the default behavior of warnings?
A) Stop script
B) Restart script
C) Continue execution
D) Delete file
✅ Answer: C
📘 Section B: Intermediate (2 Marks Each)
6. Which block is used to handle exceptions?
A) if-else
B) try-catch
C) switch
D) loop
✅ Answer: B
7. What keyword is used to throw an exception?
A) catch
B) throw
C) error
D) exception
✅ Answer: B
8. Which class is used for exceptions in PHP?
A) Error
B) Exception
C) Throwable
D) Catch
✅ Answer: B
9. What does Throwable represent?
A) Only errors
B) Only exceptions
C) Both errors and exceptions
D) None
✅ Answer: C
10. What will happen if an exception is not caught?
A) Script continues
B) Script stops with error
C) Ignored
D) Page reloads
✅ Answer: B
📙 Section C: Advanced (3 Marks Each)
11. Which function sets a custom error handler?
A) error_handler()
B) set_error_handler()
C) custom_error()
D) handle_error()
✅ Answer: B
12. Which function generates a user-defined error?
A) user_error()
B) trigger_error()
C) throw_error()
D) error_create()
✅ Answer: B
13. Which function logs errors to a file?
A) log_error()
B) error_log()
C) write_log()
D) file_log()
✅ Answer: B
14. Which is used for debugging variables?
A) echo
B) print
C) var_dump()
D) show()
✅ Answer: C
15. What is the purpose of finally block?
A) Catch error
B) Always execute code
C) Throw error
D) Stop script
✅ Answer: B
🔥 Section D: Scenario-Based (4 Marks Each)
16. What will this code do?
echo 10/0;
A) Output 0
B) Fatal error
C) Warning/Error
D) Nothing
✅ Answer: C
17. What is best practice in production?
A) Show errors
B) Hide errors and log them
C) Ignore errors
D) Stop execution
✅ Answer: B
18. Which function handles fatal errors indirectly?
A) set_error_handler()
B) register_shutdown_function()
C) catch()
D) throw()
✅ Answer: B
19. Which is better for database error handling?
A) echo
B) try-catch
C) print
D) die()
✅ Answer: B
20. White screen of death means?
A) Syntax error
B) Hidden fatal error
C) Network issue
D) Browser crash
✅ Answer: B
🏆 Score Guide
| Score | Level |
|---|---|
| 16–20 | Excellent 🔥 |
| 11–15 | Good 👍 |
| 6–10 | Average ⚠️ |
| 0–5 | Needs Improvement ❌ |






