It's useless. Since the error is currently caught, you can be as short as a bunch of memory that any new creation of an object can cause a new OOME. Having such a small maneuver in a trick means that the only action you can take is to exit.
Test this snippet and tell me your output is:
import java.util.LinkedList; import java.util.List; public class OOMErrorTest { public static void main(String[] args) { List<Long> ll = new LinkedList<Long>(); try { long l = 0; while(true){ ll.add(new Long(l++)); } } catch(OutOfMemoryError oome){ System.out.println("Error catched!!"); System.out.println("size:" +ll.size()); } System.out.println("Test finished"); } }
But, strictly speaking, yes, it is exciting.
Mister smith
source share