Exceptions And Error Handling(Php ) Questions and Answers

Question 1. Which version of PHP introduced E_STRICT Error level?
  1.    PHP 4
  2.    PHP 5
  3.    PHP 5.2
  4.    PHP 5.3
Explanation:-
Answer: Option B. -> PHP 5
Description for E_STRICT is PHP version portability suggestions

Question 2. How many error levels are available in PHP?
  1.    14
  2.    15
  3.    16
  4.    17
Explanation:-
Answer: Option C. -> 16

Question 3. What is the description of Error level E_ERROR?
  1.    Fatal run-time error
  2.    Near-fatal error
  3.    Compile-time error
  4.    Fatal Compile-time error
Explanation:-
Answer: Option A. -> Fatal run-time error

Question 4. Which character do the error_reporting directive use to represent the logical operator NOT?
  1.    /
  2.    !
  3.    ~
  4.    ^
Explanation:-
Answer: Option C. -> ~
The twidle (~) character is used to represent the logical operator NOT.

Question 5. Say you want to report error concerned about fatal run-time, fatal compile-time error and core error which statement would you use?
  1.    error_reporting = E_ALL
  2.    error_reporting = E_ERROR | E_PARSE | E_CORE_ERROR
  3.    error_reporting = E_ERROR | E_COMPILE_WARNING | E_CORE_ERROR
  4.    error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR
Explanation:-
Answer: Option D. -> error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR

Question 6. Which version of PHP was added with Exception handling?
  1.    PHP 4
  2.    PHP 5
  3.    PHP 5.3
  4.    PHP 6
Explanation:-
Answer: Option B. -> PHP 5
Exception handling was added to PHP with the version 5 release, and further enhanced with version 5.3.

Question 7. Which of the following statements invoke the exception class?
  1.    throws new Exception();
  2.    throw new Exception();
  3.    new Exception();
  4.    new throws Exception();
Explanation:-
Answer: Option B. -> throw new Exception();

Question 8. How many methods are available for the exception class?
  1.    5
  2.    6
  3.    7
  4.    8
Explanation:-
Answer: Option C. -> 7
The seven methods are: getCode(), getFile(), getLine(), getMessage(), getPrevious(), getTrace(), getTraceAsString().

Question 9. Which version added the method getPrevious()?
  1.    PHP 4
  2.    PHP 5
  3.    PHP 5.1
  4.    PHP 5.3
Explanation:-
Answer: Option D. -> PHP 5.3

Question 10. Which one of the following is the right description for the method getMessage() ?
  1.    Returns the message if it is passed to the constructor
  2.    Returns the message if it is passed to the class
  3.    Returns the message if it is passed to the file
  4.    Returns the message if it is passed to the object
Explanation:-
Answer: Option A. -> Returns the message if it is passed to the constructor