Exceptions include but are not limited to when an innocent stands to be injured by your return fire, such as if the bad guy is standing in front of a glass window that would not stop your bullet and you can see people on the other side. If the gang member is doing a drive by, you may, in most cases return fire as he is coming toward you or directly engaged in firing at you. You may not fire upon him as he is fleeing the scene, in most states. I do hope that gives you some clarification of defensive fire.
And the place in the above comment, where it say "Illegally", should read instead "illegal"