- We would like to simulate the well know "out of memory" error !
- Is it an error we can catch ?
- Is it an Exception ?
- Is it a RuntimeException ? RuntimeException is a subclass of Exception...
public static void main(String[] args) {
try {
long[][] arrayLong = new long[100000] [];
for(int i=0;i < arrayLong.length; i++) {
arrayLong[i] = new long[100000];
}
} catch(Error e) {
System.out.println("type Error was caught !!!");
System.out.println(e.getMessage());
} finally {
System.out.println("in finally...");
}
}
}
/*
rudy@vsolutions:~/Documents/SCP6/CH5$ java Exception1
type Error was caught !!!
Java heap space
in finally...
*/
- We can catch Error !
- It is NOT an Exception.
- It is not a Runtime Exception !
No comments:
Post a Comment