Fix NullPointerException if exception is in the default package

getPackage() returns null if the class is in the default package so
getPackage().getName() would result in a NullPointerException in
this scenario.

I discovered this when writing some example code for investigating an unrelated issue with Sentry.
It's a bit of an edge case but seems worth adding a fix for it.