hey guys... sorry for bugging you all but i have 1 last question and i promise that will be it.

its probably simple but i just want to know how to go about raising a custom exception

the result it expects is:

Traceback (most recent call last):
        ...
    Exception: Unrecognised label in elizas_response

but everything i try just fails :(

i tried

except Exception:
            print "Unrecognised  label  in  elizas_recollection"
            raise

but that doesnt work either. if someone can please point me in the right direction i will be very grateful

Cheers!

This is a direct quote from
http://en.wikibooks.org/wiki/Python_Programming/Exceptions

Custom Exceptions

Code similar to that seen above can be used to create custom exceptions and pass information along with them. This can be extremely useful when trying to debug complicated projects. Here is how that code would look; first creating the custom exception class:

class CustomException(Exception):
       def __init__(self, value):
           self.parameter = value
       def __str__(self):
           return repr(self.parameter)

And then using that exception:

try:
    raise CustomException("My Useful Error Message")
except CustomException, (instance):
    print "Caught: " + instance.parameter

Yah, I agree. I think you can make a module of all errors in your program and then import the module and just call them as you call a wx.Button or others. Just my 2cents !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.