Complete the code to throw an exception with the message "Error occurred".
<?php throw new [1]("Error occurred"); ?>
The Exception class is the base class for all exceptions in PHP. Using throw new Exception("Error occurred") correctly throws an exception with the given message.
Complete the code to throw a RuntimeException with the message "Runtime error".
<?php throw new [1]("Runtime error"); ?>
RuntimeException is a built-in exception class used to represent runtime errors. Throwing it with throw new RuntimeException("Runtime error") is correct.
Fix the error in the code to correctly throw an exception with the message "Invalid input".
<?php throw [1]("Invalid input"); ?>
When throwing an exception, you must use the new keyword before the exception class name. So throw new Exception("Invalid input") is correct.
Fill both blanks to throw an exception with the message "File not found" using the ErrorException class.
<?php throw new [1]("File not found", [2]); ?>
The ErrorException constructor accepts a message and an error code. Using 0 as the code is common when no specific code is needed.
Fill all three blanks to throw a LogicException with the message "Invalid operation", code 100, and previous exception stored in $prev.
<?php throw new [1]("Invalid operation", [2], [3]); ?>
The LogicException constructor accepts a message, a code, and a previous exception. Passing "Invalid operation", 100, and $prev correctly creates the exception.