I want to do this because there are several spots in my program where an error might occur that I want to handle the same way, but I don't want to rewrite the try..except block again. Is that clearer?
And I meant sys.stderr... sorry 'bout that Simon Forman wrote: > Chris wrote: > > I want to handle errors for a program i'm building in a specific way, > > but I don't want to use try/except/finally because it requires forming > > new blocks of code. I want to be able things like this: > > > > a = [2, 423, "brownie", 234.34] > > try: a[890] > > except IndexError: # I don't use 'finally' here because I specifically > > want to check for an IndexError > > sys.exit("That number is way too big!") > > > > But sometimes you can have too many of these statements in your > > program, and it starts to get tangled and nasty looking. Is there a way > > I can modify sys.error so that when the interpreter comes accross an > > IndexError it prints "That number is way too big!" before it exits? > > You don't want to do what because why? Huh? > > I'm sorry man, I don't want to be harsh, but use try..except blocks. > > If your code is getting "tangled and nasty looking" you probably need > to break it up into small[er] functions, or redesign it somehow. > > Peace, > ~Simon > > (Also, there's no such thing as sys.error, do you mean > sys.excepthook()?) -- http://mail.python.org/mailman/listinfo/python-list