Check for specific exception raised in FlagCollection instead of string content of exception

This closes one of the windows 64-bit test failures on appveyor seen in #2755