You could also log the whole stack trace using the traceback module:
http://docs.python.org/library/traceback.html

_Nik

On 5/14/2012 4:54 PM, Luis Gonzalez wrote:
> Hi as you can see here at http://docs.python.org/tutorial/errors.html
> in 8.3 handling exceptions theres a piece of code that works as you
> want.
>
> for example try this:
>
> try:
>   int("a")
> except Exception as e: #The key is using "as" and the variable name
> you like for retrieving the exception because if you dont you will
> only get
>                        #"Exception type" type
>
>   print type(e) #This will give de exception type. In this case #<type
> 'exceptions.ValueError>'
>   print e #This will print you the message exception.  #invalid
> literal for int() with base 10: 'a'
>   print e.message #This would give you the string message #invalid
> literal for int() with base 10: 'a'
>
>
> I hope this can help you, please forgive me for my grammar im mexican.
>
> On 14 mayo, 18:29, LJ <ljayad...@gmail.com> wrote:
>> I am trying to add exception handling to my application.
>> I have been reading the documentation on Django 
>> Exceptions:https://docs.djangoproject.com/en/dev/ref/exceptions/
>> I also found the list of Exceptions (both Django and Python).
>> But for testing purposes, I need a way to handle all exceptions and to
>> log the exception types:
>>
>> try:
>>    addresses = Address.objects.all()
>> except Exception:
>>   logger.debug(Exception.Type)
>>
>> How do I catch all types of exceptions?  And, how do I get the
>> exception type?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to