PHP Exception Handling MCQs
This section focuses on "Exception Handling" in PHP. These Multiple Choice Questions (mcq) and answers should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exam and other competitive examinations.
1. In Which php version Exception handling was added?
Explanation: Exception handling was added to PHP with the version 5 release, and further enhanced with version 5.3.
2. How many methods are available for the exception class?
Explanation: The seven methods are: getCode(), getFile(), getLine(), getMessage(), getPrevious(), getTrace(), getTraceAsString().
3. what is try block do?
Explanation: try: It represent block of code in which exception can arise.
4. what is finally block do?
Explanation: finally: It is used in place of catch block or after catch block basically it is put for cleanup activity in PHP code.
5. what is throw block do?
Explanation: throw: It is used to throw an exception. It is also used to list the exceptions that a function throws, but doesnâ€™t handle itself.
6. Which of the following statements invoke the exception class?
Explanation: throw new Exception(); trigger an exception and each â€œthrowâ€ must have at least one â€œcatchâ€.
7. Why Exception Handling in PHP used?
Explanation: Exception Handling in PHP used for Separation of error handling code from normal code and Grouping of error types.
8. Which of the following is not specialized keywords in exception handling.
Explanation: this keyword is not specialized keywords in exception handling.
9. How many error levels are available in PHP?
Explanation: There are 16 error levels available in PHP.
10. What is the description of Error level E_ERROR?
Explanation: A Fatal run-time error is the description of Error level E_ERROR.
Also check :