I have div() in Cal class in my CalTest class has following methods to test the div().
public fucnction div($a,$b){
if($b == 0){
throw new Exception("Divided by zero");
}
return $a/$b
}
I can pass only testDiv() but testDiv2().

I want to catch check wheather the exeption thrown correctly using PHPUnit. What am I missing here?? Your help is highly appreciated. Thank you!

Just came across the same issue. For some reason PHPUnit will not allow you to set the
expectedExceptionto a generic exception and I am not sure why. Personally I opt to throw custom Exception codes rather than have to create a new exception class every time I want to differentiate exceptions.Here is how I got around it:
This will allow you to engineer your code the way you want, and throw “generic” exceptions. Basically it just tests the Exception class and if it’s generic, re-wrap it as a different exception; Test_Exception.
— Update —
Found out yesterday that they have removed the generic exception restriction in the current “master” branch, which will be 3.7. Apparently the lead engineer has no desire of patching 3.6.