Fix so that `f` will always be defined in `except` block.