catch exceptions in java code example
Example 1: java try catch
try {
} catch(ErrorName e){
}
Example 2: try catch java
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");
}
}
}
Example 3: how do you handle exceptions in java
I use try & catch blocks to handle any exceptions in my code.
I am familiar with major checked and unchecked exceptions and
handle it accordingly to make my code execution smooth