[FIXED JENKINS-18152]

Avoid UndeclaredThrowableException by being smart about what exception to propagate and what to wrap.