1. 程式人生 > >scala中異常捕獲與處理簡單使用

scala中異常捕獲與處理簡單使用

cep something use found exception cal exceptio str 異常

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 ......")
    }

  }

}

  

scala中異常捕獲與處理簡單使用