Make panic handler safer