Multi-catch

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.

上一篇:ios创建的sqlite数据库文件如何从ios模拟器中导出


下一篇:Java豆瓣电影爬虫——小爬虫成长记(附源码)