Toplevel: catch exceptions during serialization

Exceptions can also happen during serialization, but serialization is
outside the try/with loop, so merlin process would die.