I need to retrieve the name of the object in which an error has occured. The error is catched in a try exception statement. The error type as returned by err_type, value, traceback = sys.exc_info() looks like this:
In [1]: err_type
Out[2]: mainsite.models.PurchaseOrder.DoesNotExist
I need to retrieve 'PurchaseOrder' as a string. The idea is to get the parent object and then use parent.__name__.However if I write err_type.__bases__ the result is:
In [3]: err_type.__bases__
Out[4]: (django.core.exceptions.ObjectDoesNotExist,)
I don't know what is happening here, the Exception type is not a child of PurchaseOrder, but somehow it knows that the problem was in that object. How can I retrive "PurchaseOrder" from the Exception?
I am doing this in Django, but it seems to be a general python topic.
PurchaseOrderclass also calledPurchaseOrder.py? Inmainsite.models.PurchaseOrder.DoesNotExistit looks more like it's fully qualifying the module thatDoesNotExistis from and not the object that threw the error.DoesNotExistis a nested class insidePurchaseOrder, but I agree that this output definitely does not say anything about what object was responsible for the error.PurchaseOrderfrom the exception?