Pages

Monday, 28 November 2016

Chapter 12 Exercise 10, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

12.10 (OutOfMemoryError)
Write a program that causes the JVM to throw an OutOfMemoryError and
catches and handles this error.


public class Exercise_10 {

    public static void main(String[] args) {

        try {
            int[] temp = new int[1000000000];
            temp = new int[temp.length * 1000000000];
        } catch (OutOfMemoryError ex) {
            ex.printStackTrace();
        }

    }
}

No comments:

Post a Comment