开发者

Programming languages with equivalent of the Java 7 try-multiple-catch block?

开发者 https://www.devze.com 2023-04-01 01:37 出处:网络
Java 7 features a new way to catch multiple exceptions in one catch block, as shown below. try { //stuff that causes one or more of the exceptions below.

Java 7 features a new way to catch multiple exceptions in one catch block, as shown below.

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 开发者_Python百科caught
}

What other programming languages, if any, feature a similar way to capture multiple exceptions in one block, or remove the need to use a catch block for each exception? How do these languages implement this capture of multiple exceptions?


The Ada programming language allows for the capture of multiple exception blocks, but I have no idea how this is implemented - but should be really interesting to know since Ada is VERY strongly typed. You can check the syntax here: Annotated Ada Reference Manual


Javascript requires you to catch all exceptions in one catch block, since it's not statically typed.

0

精彩评论

暂无评论...
验证码 换一张
取 消