summaryrefslogblamecommitdiff
path: root/src/library/scalax/util/control/Breaks.scala
blob: e89a03f76b0d6725125a4c5a8ceb8ae01b1d05c7 (plain) (tree)
1
2
3
4
5
6
7
8
9





                                                          
                                                       

                                                                                                   




                                
                                                 

     




                                                                
                                          
 
package scalax.util.control

object Breaks {
  private class BreakException extends RuntimeException
  private val breakException = new BreakException
  private class ContinueException extends RuntimeException
  private val continueException = new ContinueException

  /** A block from which one can exit with a `break' and which can be resumed with a `continue'. */
  def breakable(op: => Unit) {
    try {
      op
    } catch {
      case ex: BreakException =>
      case ex: ContinueException => breakable(op)
    }
  }

  /* Break from closest enclosing breakable block */
  def break { throw breakException }

  /* Continue with start of closest enclosing breakable block */
  def continue { throw continueException }
}