Python catch "unknown" exception

Unable to catch the python exception?

First, use a catch all exception and see what exception it throws. The class and module will hint at where you may import the exception to catch from.

import logging
except Exception as error:
        'unhandled exception (class=%s; module=%s)',
        error.__class__ if hasattr(error, '__class__') else 'unknown',
        error.__module__ if hasattr(error, '__module__') else 'unknown')

keywords: Django, MySQL, except ProgrammingError, django.db.utils.ProgrammingError

1 comment

  1. anonymous

    Worked. Thanks!

Leave a Reply