assertTriggerThisException ('Exception');
assertTriggerThisException ('AnotherExceptionClass');
function assertTriggerThisException ($exceptionClassname)
{
try
{
something what triggers an exception
}
catch ($$exceptionClassname $e) // error
{
}
}
所以我想传递对类本身的引用,但这会导致语法错误。我想说“dinamically”期待一个例外,有办法吗?
答案 0 :(得分:1)
我认为你可以尝试这样的事情
$someClass = 'SomeException';
try
{
$some->thing();
}
catch (Exception $e)
{
switch (get_class($e))
{
case $someClass:
echo 'Dynamic exception.';
break;
default:
echo 'Normal exception.';
}
}