Exception Handling in Java
Exception Handling in Java
}
• Test it NowOutput:
• Exception in thread "main" java.lang.ArithmeticException: / by zero
Solution by exception handling
Let's see the solution of the above problem by a java try-catch block.
Example 2
public class TryCatchExample2 {
}
Test it NowOutput:
java.lang.ArithmeticException: / by zero rest of the code
• Let's see an example to handle another unchecked exception.
public class TryCatchExample9 {
}
Test it NowOutput:
java.lang.ArrayIndexOutOfBoundsException: 10 rest of the code
Java finally block