changed rethrowing code to avoid slicing exceptions

#1010