Software Testing Topics

Try – Catch example

public class TryblockPG {

public static void main(String[] args) {

     //ArithmeticException
try{
   int a = 50/0;
      }catch(Exception e)
      {
      System.out.println(e);
      }

   System.out.println("Resume to rest of the code after arithmetic exception");

   //ArrayIndexOutofBoundException
try{ int arr[] = new int[5];
arr[0] = 10;
arr[1] = 11;
arr[2] = 12;
arr[3] = 13;
arr[4] = 14;
arr[5] = 15;
arr[6] = 16;
arr[7] = 17; }catch(Exception e)
{
   System.out.println(e);
}

   System.out.println("Resume to rest of the code after ArrayIndexOutofBound Exception");