scala中异常捕获与处理简单使用

import java.io.IOException

/**
  * 异常捕获与处理
  */
object excepitonUse {

  def main(args: Array[String]): Unit = {
    try {
      throw new IOException("throw a user define exception!!!")
    } catch {
      case e1: IOException => printf("found io exception...")
      case e2: IllegalArgumentException => {
        printf("do something when illegal happened.")
      }
    } finally {
      printf("finally ......")
    }

  }

}

  

猜你喜欢

转载自www.cnblogs.com/yxj0728/p/9281777.html