Complete the code to define a custom exception class named MyException.
<?php class MyException extends [1] { } ?>
The custom exception class must extend the built-in Exception class to behave like an exception.
Complete the code to throw a custom exception named MyException with the message 'Error occurred'.
<?php throw new [1]('Error occurred'); ?>
To throw the custom exception, use its class name MyException.
Fix the error in the code to catch the custom exception MyException.
<?php try { // some code } catch ([1] $e) { echo $e->getMessage(); } ?>
To catch the custom exception, the catch block must specify MyException.
Fill both blanks to define a custom exception class with a constructor that sets a default message.
<?php class MyException extends [1] { public function __construct() { parent::[2]('Default error message'); } } ?>
The class extends Exception and calls the parent constructor __construct with a message.
Fill all three blanks to throw and catch a custom exception, then print its message.
<?php class MyException extends Exception {} try { throw new [1]('Custom error'); } catch ([2] $e) { echo [3]; } ?>
The code throws and catches MyException and prints the exception message using $e->getMessage().