码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-07-09 00:38:13      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:catch   except   try   printf   cas   unit   some   rgs   ...   

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中异常捕获与处理简单使用

标签:catch   except   try   printf   cas   unit   some   rgs   ...   

原文地址:https://www.cnblogs.com/yxj0728/p/9281777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!