Added check for a null exception "cause" to avoid NPE

Added check for a null exception "cause" to avoid NPE when the exception doesn't have a root cause attached.
I'm happy to rename the var and re-order, no big deal. I've been using the null==[whatever] convention for years - it prevented accidental assignment rather than checks when not using an IDE to make code changes.