add exception handling to canonicalize.py