From: Travis Smith Date: 2005-08-24T02:39:00+09:00 Subject: Re: [QUIZ] Sodoku Solver (#43) On 8/23/05, Adam Shelly wrote: > So here's one thing I couldn't figure out last night, maybe someone can help me: > I wanted to throw an exception in the middle of a pair of recursive > functions, and catch it at the beginning of recursion. But I can't > figure out where to put the rescue. > I wanted to do something like this pseudocode: > > def solve > deduce > startGuessing if !solved > return solved > end > > def deduce > ...work... > raise BadGuess if conflict > end > > def startGuessing > @depth+=1 > begin > while candidates do > begin > guess #chose a candidate > cloneBoard.solve #with that candidate > rescue BadGuess > #go on to next candidate > end > end #while > raise UnsolvableBoard if !solved > rescue UnsolvableBoard if @depth == 1 # this doesn't work. > # if I remove the if, I end up at the level I started with. > # and putting the rescue in the solve function doesn't help either. > # ? So can I get back to the next candidate on the 1st level, > # without checking return codes the whole way down > # (which is what I ended up doing)? > end > end You can always recuse it, then throw it again if you don't want it. At least I assume so... I've never tried to do it in Ruby. -- ~Travis