I am sorry to learn of your difficult situation, but I congratulate you for walking out that door. I hope you took your children with you when you left; they were in just as much danger as you.
The answer to your question -- can dreams warn us of dangers that lie ahead? -- is "Yes." In fact, the great benefit of dreams, and of learning how to listen to them, is that they help us to identify awarenesses within us more quickly than if we did not have their help.
For example, had you understood the meaning of your dream at the time it occurred -- that you were in danger of lethal violence from your husband -- you might have decided to leave your marriage sooner. If you had left, you would have spared yourself and your children the threat of an increasingly violent home environment. You also wouldn't have invested an additional nineteen months of your life into what, it is clear, you already were seeing was a profoundly unhealthy partnership.
Warning dreams such as yours actually are common in all types of relationships. Whether we are beginning to date a new person or simply buying a car from an unscrupulous seller, we often register difficulties or danger at a subconscious level before we are "forced", often through painful consequence, to recognize these truths in our waking lives. The moral of the story is that if we have an intuition of danger or dishonesty -- be it a simple, waking intuition, or a feeling that results from a dream -- then we should listen to it. Most likely we have perceived something about this person at a subconscious level that is informing us that the "deal" may not be as good as it looks.
Because your dream anticipated your ex's actions so specifically, it is tempting to label the dream precognitive. From what you told us in your dream report, however, we can infer that warning signs of violence -- consistent mental abuse, "occasional" physical abuse -- actually were pervasive in your marriage. These events alone would cause most people to dream of being attacked. Also, it is important to note that the final act in this play, your being shot, thankfully never occurred. Accordingly, I don't think your dream was precognitive, but I do think it was anticipatory of difficult times ahead.
Congratulations, again, on having the courage and self-esteem to walk away.