Bird
0
0

Which of the following is the correct syntax to throw an exception with the message "Error occurred" in PHP?

easy📝 Syntax Q12 of 15
PHP - Error and Exception Handling
Which of the following is the correct syntax to throw an exception with the message "Error occurred" in PHP?
Athrow new Exception("Error occurred");
Bthrow Exception("Error occurred");
Cthrow Exception new("Error occurred");
Dthrow new Exception(Error occurred);
Step-by-Step Solution
Solution:
  1. Step 1: Recall the syntax for throwing exceptions

    In PHP, you must use throw new Exception("message") to throw an exception with a message.
  2. Step 2: Check each option for syntax correctness

    Only throw new Exception("Error occurred"); matches the correct syntax exactly. The other options either omit the new keyword, have the wrong order of keywords, or lack quotes around the message.
  3. Final Answer:

    throw new Exception("Error occurred"); -> Option A
  4. Quick Check:

    Correct syntax = throw new Exception(message) [OK]
Quick Trick: Use 'throw new Exception("message")' exactly [OK]
Common Mistakes:
  • Omitting the 'new' keyword
  • Not quoting the message string
  • Wrong order of keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes