Don't use $! inside ensure statements

Apparently doing so can cause problems, so use a separate rescue
clause to identify the exception.