[Freeipa-devel] Exception model proposal

Karl MacMillan kmacmill at redhat.com
Mon Aug 27 14:25:56 UTC 2007


On Tue, 2007-08-21 at 17:17 -0700, Kevin McCarthy wrote:
> I've been playing with the exception model, and here's my code so far.
> This uses Simo's suggestion of segmenting errors into 16 bit categories
> and 16 bit "detail" error codes.
> 
> This is not ready for committing - just wanted to get some feedback
> before I finish working on it tomorrow.
> 
> 
> All exceptions inherit from IPAError.
> 
> Sample code to throw an exception:
>     raise ipaerror.gen_exception(ipaerror.LDAP_DUPLICATE)
> 

Forcing the use of these functions seems cumbersome to me - I guess this
is caused by having a single exception type. I'd prefer to have
exception classes for each exception as it would allow you to use the
base language features for raising and filtering exceptions. You could
still have the error codes set as you have here.

Karl

> Override the message:
>     raise ipaerror.gen_exception(ipaerror.LDAP_DUPLICATE, "It's a dup")
> 
> Embed the causing error:
>    except ldap.LDAPError, e:
>       raise ipaerror.gen_exception(ipaerror.LDAP_DATABASE_ERROR, None, e)
> 
> 
> Catching a particular exception:
>     try:
>        ...
>     except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
> 
> Feedback?
> 
> Thanks,
> 
> -Kevin
> 
> 
> _______________________________________________
> Freeipa-devel mailing list
> Freeipa-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/freeipa-devel




More information about the Freeipa-devel mailing list