For some reason my code is not catching an exception when I throw it. I have
def trim_rad(rad): ... if not modrad.shape[0]: raise IndexError("Couldn't find main chunk") return modrad, thetas Then later I call that function:
try: modrad, thetas = trim_rad(rad) except IndexError("Couldn't find main chunk"): return 0 Yet I still get a traceback with that exception. What am I doing wrong?
IndexErrorthat you will be throwing and leave regular oleIndexErrorsalone, create a narrower exception type that inherits fromIndexErrorand raise/catch that.except 1:before and got a TypeError, but trying it now, it just passes through.IndexErrors, is it more standard to subclassIndexError, or parse the message and re-raise the error if it's not the specified message? I only use the error in this instance, would making a new subclass be a bit too heavy duty?