Check out example codes for "try catch java". It will help you in understanding the concepts better.

Code Example 1

public class MyClass {
  public static void main(String[ ] args) {
    try {
      int[] myNumbers = {1, 2, 3};
      System.out.println(myNumbers[10]);
    } catch (Exception e) {
      System.out.println("Something went wrong.");
    }
  }
}

Code Example 2

try {
  // Code that may have error
} catch(ErrorName e){
  // Another code
}

Code Example 3

public class MyClass {
  public static void main(String[ ] args) {
    try {
      int[] myNumbers = {1, 2, 3, 4, 5, 6};
      System.out.println(myNumbers[10]);
    } catch (Exception e) {
      System.out.println("Something went wrong. check again");
    }
  }
}

Code Example 4

try {
  //  Block of code to try
}
catch(Exception e) {
  //  Block of code to handle errors
}

Code Example 5

var person = {

    firstName: "John",

  lastName : "Doe",

    id       : 5566,

    fullName : function() {

      return this.firstName + " " + this.lastName;

    }

};

Learn ReactJs, React Native from akashmittal.com