Is it safer to keep coins in exchange?
In general no, it's not. As long as the user has some basic understanding of computer security storing coins in local wallet(s) is the best way to go. Most, if not all wallets support encryption, so that's the first thing one needs to do: encrypt the wallet file with a strong password, save the password in a safe place (use password managers, like KeyPass, or just memorize it) and that's it, you've already protected yourself from 80+% of attacks (even if they do get your wallet file, they can't do any transactions without knowing the password). That won't protect you from keyloggers though. Then there are standard security policies to implement like running the wallet on a separate machine with no other (untrusted) software, run anti-malware software, restrict network access to that machine etc. It's all outside the scope of this topic though, there's plenty of information about computer security out there, just read some guides and start implementing basic security measures on your machines/networks.
Keep in mind though that your computer is still likely to be compromised, so you'll need to clean it somehow. If you don't have an extensive network of machines and it's just one pc/laptop, I'd simply reinstall the OS completely (formatting all drives, after backing up the important data, obviously).