Mt gox and Bitfinex were attacked and a ton of bitcoins were lost. Yes exchanges can be hacked but they also can be very secure:
https://bitcoinmagazine.com/articles/how-to-secure-bitcoin-exchanges-or-why-all-hope-is-not-lost-1470764032/Problem is that a lot of exchanges are not really run by professionals, some of them turn out to be a scam after years so even if they can be extremely secure against hacks you are always in a risky situation when you leave your bitcoins on pretty much any exchange.
You personally can protect your bitcoins extremely well if you are not planning on trading with them with an offline wallet plus a few other things your bitcoins can be virtually impossible to hack although you can still lose them if you make terrible mistakes.
I personally keep my bitcoins distributed between my wallet and a few exchanges where I trade, it is, I think, the best way to make sure you lose the least amount of bitcoins at any given time.