PHP Multiple Choice Questions & Answers (MCQs) focuses on “Exception Handling”.
Q 1. Which version of PHP was added with Exception handling?
A. PHP 4
B. PHP 5
C. PHP 5.3
D. PHP 6
Show Answer
Answer:-B. PHP 5Explanation
Exception handling was added to PHP with the version 5 release, and further enhanced with version 5.3.
Q 2. How many methods are available for the exception class?
A. 5
B. 6
C. 7
D. 8
Show Answer
Answer:-C. 7Explanation
The seven methods are: getCode(), getFile(), getLine(), getMessage(), getPrevious(), getTrace(), getTraceAsString().
Q 3. Which of the following statements invoke the exception class?
A. throws new Exception();
B. throw new Exception();
C. new Exception();
D. new throws Exception();
Show Answer
Answer:-B. throw new Exception();Explanation
throw new Exception(); trigger an exception and each “throw” must have at least one “catch”.
Q 4. Which version added the method getPrevious()?
A. PHP 4
B. PHP 5
C. PHP 5.1
D. PHP 5.3
Show Answer
Answer:-D. PHP 5.3Explanation
The function getPrevious() returns previous exception.
Q 5. Which one of the following is the right description for the method getMessage()?
A. Returns the message if it is passed to the file
B. Returns the message if it is passed to the class
C. Returns the message if it is passed to the constructor
D. Returns the message if it is passed to the object
Show Answer
Answer:-C. Returns the message if it is passed to the constructorExplanation
The function getMessage() gets the exception message. It returns the message if it is passed to the constructor.Q 6. What does SPL stand for?
A. Source PHP List
B. Source PHP Library
C. Standard PHP List
D. Standard PHP Library
Show Answer
Answer:-D. Standard PHP LibraryExplanation
The standard PHP library(SPL) extends PHP by offering ready-made solutions to commonplace tasks such as file access, iteration of various sorts etc.Q 7. You can extend the exception base class, but you cannot override any of the preceding methods because the are declared as__________
A. protected
B. final
C. static
D. private
Show Answer
Answer:-B. finalExplanation
Marking a method as final prevents it from being overridden by a subclass.
Q 8. How many predefined exceptions does SPL provide access to?
A. 13
B. 14
C. 15
D. 16
Show Answer
Answer:-A. 13Explanation
It provides 13 exceptions: BadFunctionCallException, BadMethodCallException, DomainException, InvalidArgumentException, LengthException, LogicException, OutOfBoundsException, OutOfRangeException, OverflowException, RangeException, RuntimeException, UnderflowException, UnexpectedValueException.Q 9. Which of the following is/are an exception?
i) OutOfBoundException
ii) OutOfRangeException
iii) OverflowException
iv) UnderflowException
A. i)
B. i) and iii)
C. i) and ii)
D. i), ii), iii) and iv)
Show Answer
Answer:-D. i), ii), iii) and iv)Explanation
The exception is thrown if a value is not a valid key. This represents errors that cannot be detected at compile time. OutOfBoundException, OutOfRangeException, OverflowException, UnderflowException are valid exceptions in PHP.
Q 10. Which of the following is/are an exception?
i) BadFunctionCallException
ii) BadMethodCallException
iii) LogicException
iv) DomainException
A. Only ii)
B. Only iii)
C. i), ii), iii) and iv)
D. Only iv)
Leave a Reply