New gauge anomalies and topological invariants in various dimensions