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"

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


This is a direct quote from

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:

    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 !

This article has been dead for over six months. Start a new discussion instead.