Catch exceptions in main.py

Fixes #31.