How to generally handle exceptions?

Michael Ströder michael at stroeder.com
Wed Oct 24 11:11:14 CEST 2001


Nick Bower wrote:
> 
> Is there any possible way to tell what exception has been raised in
> python-ldap without catching every single possibile type of
> _ldap.LDAPError?
> 
> It would be really nice in example included in the python-ldap
> documentation if an exception was caught in the following general way:
> 
> try:
>   <connect, bind and search, as is currently shown>
> except:
>   <display type of exception and its description>
> 
> at the moment, there is no example code with exceptions in the
> documentation or distribution and i can't figure out how to catch one
> from the exception references provided without trying to catch every
> single possibility.

import ldap

try:
    <connect, bind and search, as is currently shown>
except ldap.LDAPError,e:
    print repr(e)

Well, exception instances are not really implemented completely
pythonic but it's a start.

Ciao, Michael.




More information about the python-ldap mailing list