changed unpack_exception to use hasattr for robustness