Added default value for err variable.

Not sure if this is the best style - maybe it should be in a `finally` clause?