The first definition of dramatic irony I learned (sixteen years ago) was the audience or the readers knowing what the characters did not. That’s a simple way to express what can be a very complex and powerful tool in a novelist’s bag of tricks. Dramatic irony can occur in every genre, and it can be used in different ways.
1. An alert to the readers
When the three witches mention Macbeth’s name at the start of the play, that’s something the other characters have no idea about, but the audience does. We know that a dark purpose is in motion, that something ominous is going to befall Macbeth, and soon enough it does.
Dramatic irony walks a line here. If not for the single mention of Macbeth’s name, the witches would have seemed to come out of nowhere when they confronted Macbeth, and yet they don’t need to make their intentions explicit. Dramatic irony does best when it’s not heavy-handed, when it doesn’t spell out too much of what’s to come or belabor the point. The characters should never be aware that what they’re saying is portentous.
2. Raising tension for the readers
At its best, dramatic irony should make readers want to shout or plead with the characters to listen, to wait, to run, to draw back. A long time ago, I wrote a story which I think of as a Cautionary Tale because I made so many amateur mistakes in it, but there was one moment I still like. An assassin set out to kill the protagonist, and took passage with some mummers called Mallekho’s Players. Meanwhile, the protagonist kissed his wife and children goodbye and set out to confront his enemies (who had hired the assassin). As he rode out from the city, he passed a chain of brightly painted wagons with the words “Mallekho’s Players” on the side.
Dramatic irony is similar to foreshadowing this way: it hints that something bad is going to happen. One difference, to me, is that dramatic irony is more specific – and as a result, produces far more tension. I could have had the protagonist riding out under a flock of crows perched on the bare branch of a cypress tree – both symbols of death – but that would have been far too subtle. It wouldn’t have been clear exactly where the danger lay.
Dramatic irony is also different from (and more effective than) the omniscient narrator viewpoint used incorrectly. Dramatic irony always arises from the characters not having all the necessary information, or not putting it together correctly, rather than not being privy to the narrative.
Julia's estranged husband sent her an envelope containing the key to a hotel room. The note inside said that he was sorry about the affair and knew they had a lot to talk about. “Be there at eight tonight,” he wrote. “And don’t tell anyone. It’ll be easier to enjoy each other’s company without your family calling to check on the reconciliation.”
For me, this works a lot better than spelling it out for the readers.
Julia's estranged husband sent her an envelope containing the key to a hotel room. What she didn’t realize at the time was that he had no intention of meeting her, much less reconciling with her.
3. A source of humor
My favorite Shakespearan comedy Twelfth Night, revolves around dramatic irony. Even gritty fantasies like A Song of Ice and Fire occasionally use this device to milk wry humor from situations. When Arya finds Elmar Frey crying over the fact that his betrothal to a princess has fallen through, neither of them realizes that she’s the princess. I thought that was funny. Of course, Martin promptly scared me again by having Arya, angry with Elmar’s selfishness, wish that his princess would die.
Dramatic irony can really manipulate readers' emotions, in other words. And that's a good thing.

