I have some modules that I've written, called from a Web2Py controller. I use this: class CustomException(Exception): def __init__(self, errno, strerror): self.errno = errno self.strerror = strerror def __str__(self): return repr(str(self.errno)+"-"+self.strerror)
Down in my lowest module, I have this: from CustomException import CustomException class Invoices(object) def __init__(self,db,customer_id): self.db=db self.customer_id=customer_id self.rows =db(db.invoices.customer_id==self.customer_id) \ .select(orderby=~db.invoices.invoice_date) if None==self.rows: raise CustomException(1,"No invoices found") if 0==len(self.rows): raise CustomException(2,"No invoices found") self.current = 0 self.high=len(self.rows) So I expect that I can try/except this. Here's my code, with some syslog statements. I'll post the syslog output afterwards. syslog(str(CustomException)) try: rows=Invoices(db,self.customer_id) except CustomException.CustomException: rows=[] except: syslog( "Unexpected error:"+ str(sys.exc_info()[0])) raise Imagine my surprise when I wind up in the catchall except. Especially given these two syslog entries: Mar 22 23:00:41 admin01 httpd: <module 'applications.gw.modules.CustomException' from 'applications/gw/ modules/CustomException.py'> Mar 22 23:00:41 admin01 httpd: Unexpected error:<class 'applications.gw.modules.CustomException.CustomException'> The two classes match, yet I cannot catch the exception. I hope somebody can point out the error of my ways... Ed Greenberg