Fixed Exceptions not throwing due to if condition not being inverted.
Added unit test to provide examples.