DreadfulProblemException.java Source code

Java tutorial

Introduction

Here is the source code for DreadfulProblemException.java

Source

class DreadfulProblemException extends ArithmeticException {
    public DreadfulProblemException() {
    }

    public DreadfulProblemException(String s) {
        super(s);
    }
}

public class MainClass {
    public static void main(String[] a) {
        int[] array = new int[] { 1, 0, 2 };
        int index = 0;
        try {
            System.out.println("First try block in divide() entered");
            array[index + 2] = array[index] / array[index + 1];
            System.out.println("Code at end of first try block in divide()");
        } catch (ArithmeticException e) {
            System.out.println("Arithmetic exception caught in divide()");
            throw new DreadfulProblemException("index + 1"); // Throw new exception
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Index-out-of-bounds index exception caught in divide()");
        }
        System.out.println("Executing code after try block in divide()");
    }
}