On Feb 17, 2010, at 7:21 PM, Jeff Johnson wrote:

> I am trying to wrap my arms around exceptions.  I see in code:
> 
> Try:
>     ...
> Except myFineException
> 
> I have looked at built in exceptions and I see them in tracebacks.
> 
> When I look at dExceptions.py I see:
> 
> class NoRecordsException(dException):
>       pass
> 
> What does this do?  Does it just say that a NoRecordsException is Ok? 
> Do you add code to it somewhere else?  Or does this just print on the 
> traceback?

        No, this just defines the class. The class doesn't "do" anything, it 
just provides a particular type of exception. That way, somewhere in the code 
when no records are returned from a query, we can add code that says:

if self.RowCount == 0:
        raise dException.NoRecordsException

        The calling method (usually in the form or the bizobj) can then add a 
handler for this particular class of exception. So let's say it's a form. The 
call might look like:

try:
        self.requery()
except dException.NoRecordsException:
        dabo.ui.info("Sorry, no records matched your criteria")
except dException.DBQueryException:
        dabo.ui.info("Your query was not formed correctly")
except dException.ConnectionLostException:
        dabo.ui.info("The database connection was lost. Try again later")

        What the above code does is catch different types of exceptions, and 
handle them appropriately. In other languages, the more common method is to 
return different error codes, but in Python, it is more common to raise 
different exception classes based on the particular problem.

> PS.  Ed, don't answer this.  It sounds from your last joke like you 
> haven't been getting any sleep preparing for PyCon!   ;^)


        Oh, man, you're crusin' for a bruisin'!


-- Ed Leafe



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

Reply via email to