Replaced exception with startswith in GraphConnectivity

It is more Java like.