Use the interjection ahem when you want to get someone's attention in a low-key way. If a class is being noisy, the teacher may say, "Ahem, class. Let's turn our attention to the periodic table of the elements now."
Ahem mimics the sound of a person clearing their throat, so you can use it any time you might naturally do some throat-clearing. In addition to getting attention, saying ahem can also express disapproval, embarrassment, or hesitation. If your overhear your friends talking about you, you might say, "Ahem. I'm standing right here."