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

Multi-catch

时间:2015-02-06 16:25:23      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

It’s relatively common for a try block to be followed by several catch blocks to handle various types of exceptions. If the bodies of several catch blocks are identical, you can use the multi-catch feature (introduced in Java SE 7) to catch those exception types in a single catch handler and perform the same task. The syntax for a multi-catch is:

catch (Type1 | Type2 | Type3 e)

Each exception type is separated from the next with a vertical bar (|). The preceding line of code indicates that any of the types (or their subclasses) can be caught in the exception handler. Any number of Throwable types can be specified in a multi-catch.

Multi-catch

标签:

原文地址:http://www.cnblogs.com/IcanFixIt/p/4277401.html

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