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'