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.
精彩评论