The stock exchange is not necessary but it’s one of the most complete markets and it’s one of the easiest ways for companies to raise capital and for investors to invest their funds in companies that suit their investing needs.
I would not say that it’s necessary but you can definitely say that it’s helpful for the economy especially when you consider that a lot of companies have quick and easy access to funds that otherwise would be hard to find and more expensive to convince to invest in your business.