Java7 : Multiple Catch Block with example

September 12, 2015 ・0comments


With JAVA SE 7, Multi-catch exceptions handling has been introduced and it is a convinent way for exception handling, since we can catch multiple exceptions using one catch block.

In the "Multi-catch" block each exception should be separated by pipe (|) character and that will make code is more readable.

Read more : Working with Java SE 7 

Ex:
public class SampleClass {
    public static void main(String[] args) {
        try {
            // Your code
        } catch (ParseException | IOException exception) {
            // inside the multie catch block
        }
    }
}

Post a Comment