Ed Leafe schrieb:
> On Jan 25, 2009, at 1:51 PM, Christoph Zwerschke wrote:
> 
>>> in scanChangedRows
>>>    raise e
>>             ^
>>
>> I think we should use a bare "raise" statement here so the error is
>> re-raised including its original traceback. The "raise e" here  
>> discards
>> the traceback so we can't see the real cause of the reported problem.
>> Sometimes less is more.
> 
>       Yes, that's ancient code. I was told once that once an error was  
> caught, it had to be explicitly re-raised again, so that's why that  
> syntax exists. I've just replaced all of them with the simpler 'raise'.

That advice was probably given because, if another exception happens 
inside the exception handler, the bare "raise" statement will raise that 
last exception instead of the original exception.

I.e. in the following example,

try:
     raise Exception("First")
except Exception, e:
     try:
         raise Exception("Second")
     except:
         pass
     raise

the second exception is raised which is probably not what you want.

If you use "raise e" instead of "raise", then the first exception is 
raised, but you lose the traceback.

The only solution I'm aware of that does not have one of these 
disadvantages is the following:

try:
     raise Exception("First")
except Exception:
     e = sys.exc_info()
     try:
         raise Exception("Second")
     except: # we don't care
         pass
     raise e[0], e[1], e[2]

-- Christoph

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[email protected]

Reply via email to