Fix re-raising exceptions in locked file to preserve stack trace.