It's a very strange situation for you to be in, to have miscarried before you even knew you were pregnant, and therefore to have to deal with both those pieces of information at once. If you had found out you were pregnant, what would you have done?
This must have come as a huge shock to you, so I really think you need some support from someone. Your ex will need to know, but he doesn't have to be the first - how about a friend or your mum, so you can talk it through and sort it out in your own mind before you tell him?