class LoopError(Exception):pass rs = '' try: for i in range(1, 3): print i rs = 'one ' if i == 1: for j in range(12, 22): print j if j == 13: rs = 'bbs' raise LoopError except LoopError: #跳出,遇到LoopError print rs print 'good' else: #循环完毕,没抛出LoopError print 'Not found'