[openstack-dev] [Review] Use of exception for non-exceptional cases

Monty Taylor mordred at inaugust.com
Wed Jul 10 23:49:23 UTC 2013

I'd like top-post and hijack this thread for another exception related

a) Anyone writing code such as:

except SomeException:
  raise SomeOtherExceptionLeavingOutStackContextFromSomeException

should be mocked ruthlessly.

Similarly, we toss tons of exceptions into log files right now for
things that are just normal operational error conditions. We should stop
doing that.

On 07/10/2013 02:01 PM, Nachi Ueno wrote:
> HI folks
> I would like to ask the review criteria in the community.
> Should we use exception for non-exceptional cases when we can use
>  parameter checking?
> Example1:  Default value for array index
> try:
>    value = list[5]
> except IndexError:
>     value = 'default_value'
> This can be also written as,
>      list_a[3] if len(list_a) > 3 else 'default_value'
> "ask for forgiveness, not permission" is one of way in python,
> however, on the other hand, google python code style guide says,
> -------------
> Minimize the amount of code in a try/except block. The larger the body
> of the try, the more likely that an exception will be raised by a line
> of code that you didn't expect to raise an exception. In those cases,
> the try/except block hides a real error.
> ---------------
> http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Exceptions
> Personally, I prefer not to use exception for such cases.
> Best
> Nachi
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

More information about the OpenStack-dev mailing list