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

2013-07-13 Thread Robert Collins
On 11 July 2013 20:50, Mark McLoughlin mar...@redhat.com wrote: That answer does begin with this, though: I almost always use hasattr: it's the correct choice for most cases. I have to disagree here, hasattr is basically a timebomb. Three-param getattr, or safe_hasattr are *much* better

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

2013-07-12 Thread Monty Taylor
On 07/11/2013 05:20 AM, Mark McLoughlin wrote: On Wed, 2013-07-10 at 19:49 -0400, Monty Taylor wrote: I'd like top-post and hijack this thread for another exception related thing: a) Anyone writing code such as: try: blah() except SomeException: raise

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

2013-07-12 Thread Monty Taylor
On 07/11/2013 05:43 AM, Thomas Hervé wrote: On Thu, Jul 11, 2013 at 1:49 AM, Monty Taylor mord...@inaugust.com mailto:mord...@inaugust.com wrote: I'd like top-post and hijack this thread for another exception related thing: a) Anyone writing code such as: try:

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

2013-07-12 Thread Monty Taylor
On 07/11/2013 05:43 AM, Thomas Hervé wrote: On Thu, Jul 11, 2013 at 1:49 AM, Monty Taylor mord...@inaugust.com mailto:mord...@inaugust.com wrote: I'd like top-post and hijack this thread for another exception related thing: a) Anyone writing code such as: try:

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

2013-07-12 Thread Monty Taylor
On 07/11/2013 06:22 AM, Sean Dague wrote: On 07/11/2013 05:43 AM, Thomas Hervé wrote: On Thu, Jul 11, 2013 at 1:49 AM, Monty Taylor mord...@inaugust.com mailto:mord...@inaugust.com wrote: I'd like top-post and hijack this thread for another exception related thing: a)

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

2013-07-12 Thread Thomas Hervé
On Fri, Jul 12, 2013 at 5:33 PM, Monty Taylor mord...@inaugust.com wrote: On 07/11/2013 05:43 AM, Thomas Hervé wrote: On Thu, Jul 11, 2013 at 1:49 AM, Monty Taylor mord...@inaugust.com mailto:mord...@inaugust.com wrote: I'd like top-post and hijack this thread for another

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

2013-07-12 Thread Dolph Mathews
On Fri, Jul 12, 2013 at 10:09 AM, Monty Taylor mord...@inaugust.com wrote: On 07/11/2013 05:20 AM, Mark McLoughlin wrote: On Wed, 2013-07-10 at 19:49 -0400, Monty Taylor wrote: I'd like top-post and hijack this thread for another exception related thing: a) Anyone writing code such

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

2013-07-12 Thread Nachi Ueno
Hi folks Monty Thank you for your adding good topic for this. I agree, hiding true cause by exception get hard to debug For, example, Sqlalchemy gives me this error for general sql errors.. exceptions must be old-style classes or derived from BaseException, not str (It should be hidden from

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

2013-07-12 Thread Brant Knudson
Somewhat offtopic, but others might find it interesting. On another project I used a different technique for exceptions, where the original exception is enhanced with new fields as it propagates up the stack to where it's handled. In this way all the information needed to handle the exception is

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

2013-07-12 Thread Mark Washenberger
I'm curious if folks know about this? import sys def foo(): raise Exception('Foo Exception') def bar(): try: foo() except Exception: exc_info = sys.exc_info() raise Exception('Bar Exception'), None, exc_info[2] bar() Traceback (most recent call last):

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

2013-07-11 Thread Mark McLoughlin
On Wed, 2013-07-10 at 21:14 +0200, Thomas Hervé wrote: On Wed, Jul 10, 2013 at 8:32 PM, Mark McLoughlin mar...@redhat.com wrote: On Wed, 2013-07-10 at 11:01 -0700, Nachi Ueno wrote: Personally, I prefer not to use exception for such cases. The key

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

2013-07-11 Thread Mark McLoughlin
On Wed, 2013-07-10 at 19:49 -0400, Monty Taylor wrote: I'd like top-post and hijack this thread for another exception related thing: a) Anyone writing code such as: try: blah() except SomeException: raise SomeOtherExceptionLeavingOutStackContextFromSomeException should be mocked

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

2013-07-11 Thread David Stanek
On Thu, Jul 11, 2013 at 5:20 AM, Mark McLoughlin mar...@redhat.com wrote: But I think what you're saying is missing is the stack trace from the underlying exception. As I understood it, Python doesn't have a way of chaining exceptions like this but e.g. Java does. A little bit more poking

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

2013-07-10 Thread Nachi Ueno
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

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

2013-07-10 Thread Dolph Mathews
On Wed, Jul 10, 2013 at 1:01 PM, Nachi Ueno na...@ntti3.com 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]

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

2013-07-10 Thread Mark McLoughlin
On Wed, 2013-07-10 at 11:01 -0700, 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

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

2013-07-10 Thread Nachi Ueno
Hi Mark Thank you for your answering I don't think this statement contradicts the intent of EAFP. I got it :) Personally, I prefer not to use exception for such cases. My instinct is the same, but EAFP does seem to be the python way. There are times I can tolerate the EAFP approach but,

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

2013-07-10 Thread Thomas Hervé
On Wed, Jul 10, 2013 at 8:32 PM, Mark McLoughlin mar...@redhat.com wrote: On Wed, 2013-07-10 at 11:01 -0700, Nachi Ueno wrote: Personally, I prefer not to use exception for such cases. The key here is personally. I don't think we have to agree on all style issues. My instinct is the

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

2013-07-10 Thread Nachi Ueno
Hi Thomas Thank you for your reply. The key here is personally. I don't think we have to agree on all style issues. personally is why I'm asking it for communities. IMO, we should agree on the style issue as much as we can. (Eg pep8, flake8) for more consistant review. However, I also agree

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

2013-07-10 Thread David Ripton
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

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

2013-07-10 Thread Doug Hellmann
On Wed, Jul 10, 2013 at 3:57 PM, David Ripton drip...@redhat.com wrote: 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

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

2013-07-10 Thread Dolph Mathews
On Wed, Jul 10, 2013 at 3:30 PM, Doug Hellmann doug.hellm...@dreamhost.comwrote: On Wed, Jul 10, 2013 at 3:57 PM, David Ripton drip...@redhat.com wrote: 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