Test that the correct exception is thrown.