Java 7 提供了一种在一个 catch
block 中捕获多个异常的新方法,如下所示。
try
{
//stuff that causes one or more of the exceptions below.
}
catch (IOException | IllegalArgumentException | IndexOutOfRangeException ex)
{
//one of the above exceptions was thrown and caught
//this code block will run if any of the above exceptions was caught
}
还有哪些其他编程语言(如果有的话)具有类似的方法来在一个 block 中捕获多个异常,或者无需为每个异常使用 catch
block ?这些语言如何实现这种对多个异常的捕获?
最佳答案
Ada 编程语言允许捕获多个异常 block ,但我不知道这是如何实现的——但应该很有趣,因为 Ada 是非常强类型的。您可以在此处检查语法:Annotated Ada Reference Manual
关于java - 具有等效于 Java 7 try-multiple-catch block 的编程语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7270346/