If I understand what you're trying to do correctly, then no, because when you include the file that has the class that throws CustomException
, it will include the CustomException class already.
Consider the following situation, where we have a main file which includes a file (which includes a file itself):
main.php:
include("include1.php");
var_dump($variable_defined_in_include2);
include1.php:
include("include2.php");
include2.php:
$variable_defined_in_include2 = true;
Even though main.php doesn't include include2.php, $variable_defined_in_include2
will be set because include1.php is included, which includes include2.php.