浏览 1813 次
锁定老帖子 主题:scala break
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2018-09-27  
import org.junit.{Before, BeforeClass, Test}
import org.scalatest.junit.JUnitSuite

import scala.util.control.ControlThrowable

private class BreakControl extends ControlThrowable

object ScalaBreaksTest {
  @BeforeClass
  def _init : Unit = {

  }
}

class ScalaBreaksTest extends JUnitSuite {

  private val breakException = new BreakControl

  def init : Unit = BreaksTest._init

  @Before
  def inittest() : Unit = {}

  @Test
  def test() : Unit = {
    var i: Int = 0
    try {
      while (i < 100) {
        i = i + 1
        if (i == 5) {
          throw breakException
        }
      }
    } catch {
      case ex: BreakControl =>
        if (ex ne breakException) throw ex
    }
    println(i)
    assert (5 == i, "i must eq 5")
  }
}
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics