The instanceof thing would work, but
a) getMessage is AFAIK a method of Exception too, so you can simply call it on e without any casting.
b) Have several catch blocks with diffferent classes. It's more efficient.