Deal with exceptions

Surround the whole block in try-except