Social Icons

twitterfacebookgoogle pluslinkedinrss feed Online Resume

Friday, September 11, 2015

Java7 : Multiple Catch Block with example


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 (|) charatcter 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