I'm trying to create my own exceptions, but encountered a problem...
class MyException extends Exception {
MyException (String w) { super ( w ); }
};
public class RozkladLiczby{
private int[] Array;
RozkladLiczby(int n) throws MyException {
try{
Array = new int[n+2];
}
catch(OutOfMemoryException ex){
throw new MyException ("Not enough memory" );
}
}
}
Compiler says it can't find symbol in catch.
RozkladLiczby.java:16: error: cannot find symbol
catch(OutOfMemoryException ex){
^
symbol: class OutOfMemoryException
location: class RozkladLiczby
1 error
That's because there is no OutOfMemoryException in Java; there is OutOfMemoryError. And if there's no memory left, then what can you do? There's no memory to create your new exception. That's why it's an Error and not an Exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With