Skip to content

Commit

Permalink
Clean up exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Landelle committed Dec 12, 2012
1 parent 230a339 commit 48b24f1
Showing 1 changed file with 10 additions and 13 deletions.
Expand Up @@ -54,24 +54,21 @@ class WhileAction(condition: Expression[Boolean], val next: ActorRef, val counte

val sessionWithTimerIncremented = increment(init(session))

val evaluatedCondition = try {
condition(sessionWithTimerIncremented)
} catch {
case e: Exception =>
error("Condition evaluation crashed", e)
"Condition evaluation crashed, exiting loop".failure
}
// as WhileAction is not supervised, there's no one to restore its state (loopNextAction) on crash, so we try to avoid it
val evaluatedCondition =
try condition(sessionWithTimerIncremented)
catch {
case e: Exception =>
error("Loop condition evaluation crashed", e)
("Loop condition evaluation crashed: " + e.getMessage).failure
}

evaluatedCondition match {
case Success(evaluatedCondition) =>
if (evaluatedCondition)
loopNextAction ! sessionWithTimerIncremented
else
next ! expire(session)
case Success(true) => loopNextAction ! sessionWithTimerIncremented
case Success(false) => next ! expire(session)
case Failure(message) =>
error("Error, exiting loop " + message)
next ! expire(session)
}

}
}

0 comments on commit 48b24f1

Please sign in to comment.