[Zope-DB] catching sql method exceptions inside python scripts

Jim Abramson jabramson at wgen.net
Fri Apr 2 13:09:34 EST 2004


Hi Chris,

Thanks for replying.

Well, the point of the current exercise is a monitoring script that tells me when the 
pool's gone sour - since this doesn't fix itself automatically. I run some simple sql
and see if anything goes wrong.

The error is this:

(2.6.1)
Module Shared.DC.ZRDB.DA, line 399, in __call__

399:        try: DB__=dbc()
400:        except: raise 'Database Error', (
401:            '%s is not connected to a database' % self.id)

I'm no py stud, but I don't think there's any special glove I can use to catch this.
"except Exception" sure doesn't work. Maybe there is another way?

Perhaps the old hack-the-source ploy. Or is it changed in a more recent release?

Best,
Jim


> -----Original Message-----
> From: Chris Withers [mailto:lists at simplistix.co.uk]
> Sent: Friday, April 02, 2004 3:34 AM
> To: Jim Abramson
> Cc: zope-db at zope.org
> Subject: Re: [Zope-DB] catching sql method exceptions inside python
> scripts
> 
> 
> Jim Abramson wrote:
> 
> > It seems that
> > 
> > try:
> >    mySqlMethod()
> > except:
> >    # handle the error...
> > 
> > is useless in python scripts...Zope springs up an error 
> page anyway.  
> 
> That's suprising, what's the error that springs up?
> 
> > Anyone else found this to be the case?  Is this by design?  
> 
> No, but bare try/except's like that will bite you on the ass 
> in so many new and 
> unpleasant ways, I really would recommend against them!
> 
> cheers,
> 
> Chris
> 
> -- 
> Simplistix - Content Management, Zope & Python Consulting
>             - http://www.simplistix.co.uk
> 
> 



More information about the Zope-DB mailing list